Skip to content
daisuke nishino edited this page Oct 17, 2018 · 2 revisions

Open Touryo Tutorial (ASP.NET Web Forms application (C#) edition)

November 27th, 2014

Introduction

Objective of this document

The objective is to learn the development of ASP.NET Web Forms application using Open Touryo framework, by developing sample programs according to the exercises in this tutorial. This tutorial explains the generation of scripts and class files by using the tool, flow and functionality of ASP.NET Web Forms application with an example.

Scope of this document

Scope of this tutorial is learning how to use Open Touryo framework in ASP.NET Web Forms application.

Overview of this document

This tutorial describes the development flow for ASP.NET Web Forms application by using Open Touryo framework. The sample program attached to Open Touryo Visual Studio 2015 template base (/root_VS2015/) is used as the material of this tutorial.

As we are pressed for time, some images are only displayed in Japanese.

Use of copyrights and trademarks of other companies

The company names and product names used in this document are the trademarks or registered trademarks of the respective companies.

License

This document can use Creative commons CC BY 2.1 JP license.

Table of Contents

1. Overview of Open Touryo framework

2. Set up the environment

3. Exercises in this tutorial

4. Exercises

1. Overview of Open Touryo framework

Open Touryo framework is an application framework for .NET. Open Touryo framework targets .NET Framework 4.6 or above and can be used in various applications like C/S (Windows Forms, WPF), Web (ASP.NET) and RIA (Silverlight).

Figure 1-1 shows the class configuration of Open Touryo framework.

Figure 1-1 Class diagram of Open Touryo framework

This tutorial explains how to create Screen / Business logic class / Data access class to be implemented by developer according to Class configuration diagram - Figure 1-1.

2. Set up the environment

The followings are the prerequisites for this tutorial.

  • Development environment
    • IDE
      • Visual Studio 2015 (Express Edition is also available)
    • Application framework
      • Open Touryo Template Base for Visual Studio 2015
  • Runtime environment
    • Runtime
      • .NET Framework 4.6
    • Web Server
      • IIS Express
    • DB
      • SQL Server Express 2008 R2
  • Others
    • OS
      • Windows 7
    • Programming language
      • Visual Basic
    • Browser
      • Internet Explorer 11

Install Visual Studio referring to Microsoft homepage beforehand.

Next, set up Open Touryo Template Base and database.

  1. Click [Download ZIP] button on GitHub and obtain OpenTouryoTemplates.zip. Unzip this zip file and obtain Open Touryo Template Base for Visual Studio 2015.

  2. Set up Open Touryo Template Base and database according to Readme.md in root_VS2015 folder.

3. Exercises in this tutorial

Users of this tutorial can practice by adding screen or logic to the sample program that bundled with Open Touryo template base. Figure 3-1 shows the configuration of sample program and Figure 3-2 shows the Screen transition diagram of the tutorial.

Figure 3-1 Configuration of sample program

When the exercise of this tutorial is completed, three types of class, indicated in the following table, are created for data access class. For details on these classes, refer User guide of Open Touryo (Better use and FAQ Edition).

Data Access class Explanation
Auto generation DAO DAO class that is generated by D layer auto generation tool bundled with Open Touryo template base. This class is used while performing simple CRUD process in table/view.
Common DAO DAO class that is provided by Open Touryo framework. This class is used when D layer auto generation tool can not be used, such as the case of obtaining the result based on joined tables.
DAO summary class Facade class in D layer. This class is used for summarizing requests from business logic class when using multiple DAO classes in one transaction.

Figure 3-2 Screen transition diagram of tutorial

4. Exercises

The following section describes development flow using Open Touryo framework.

4.1 Launch Visual Studio

  1. Open C:\root\programs\C#\Samples\WebApp_sample\ProjectX_sample\ProjectX_sample.sln.

  2. Confirm that Visual Studio is launched and the sample program that bundled with Open Touryo template base is opened.

4.2 Create presentation layer (Screen design)

4.2.1 Create master page

  1. In Solution Explorer, select Aspx\Common folder. Click Project -> Add New Item in toolbar.

  2. Select Web Forms Master Page and add new master page named TouryoMaster.master.

  3. To add JavaScript and hidden tags used by Open Touryo in the master page, implement master page as follows referring to existing master page. (e.g. Aspx\Common\TestBlankScreen.master)

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="TouryoMaster.master.vb" Inherits="ProjectX_sample.Aspx.Common.TouryoMaster" %>
    
    <!-- All Rights Reserved, Copyright (C) 2007,2012 Hitachi Solutions,Ltd. -->
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>無題のページ</title>
        <!--Uncomment below line when using jQuery-->
        <!--<script src="http://code.jquery.com/jquery-3.1.0.min.js"></script>-->
    
        <!--FxCode:add-start-->
        <script type="text/javascript" src="<%= this.ResolveClientUrl("~/Framework/js/common.js") %>"></script>
        <script type="text/javascript" src="<%= this.ResolveClientUrl("~/Framework/js/ie_key_event.js") %>"></script>
    
        <!-- Resolve URL in the javascript-->
        <script type="text/javascript">
                var baseUrl = "<%= ResolveUrl("~/") %>";
        </script>
    
        <!-- IE8をIE7互換モードで動作させる -->
        <!--meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /-->
    
        <link rel="stylesheet" href="<%= this.ResolveClientUrl("~/Css/style.css") %>" type="text/css"/>
        <!--FxCode:add-end-->
    </head>
    
    <!--FxCode:add-js-event-->
    <body onload="Fx_Document_OnLoad();" onunload="Fx_Document_OnClose();">
    
        <!-- オートコンプリートを指定 -->
        <form id="form1" runat="server" autocomplete="on">
            <!-- Common header -->
            <h1>Open Touryo sample</h1>
    
            <!--SampleCode:add-start-->
    
            <a href="<%= this.ResolveUrl("~/Aspx/start/menu.aspx") %>">メニュー画面</a><br />
            <!--SampleCode:Contents-->
            <asp:contentplaceholder id="ContentPlaceHolder_A" runat="Server">
                    This is Default Content -- Override on Page
            </asp:contentplaceholder>
            <!--SampleCode:add-end-->
    
            <!--FxCode:add-start-->
            <asp:HiddenField ID="ChildScreenType" runat="server" Value="0" />
            <asp:HiddenField ID="ChildScreenUrl" runat="server" Value="0" />
            <asp:HiddenField ID="CloseFlag" runat="server" Value="0" />
            <asp:HiddenField ID="SubmitFlag" runat="server" Value="0" />
            <asp:HiddenField ID="ScreenGuid" runat="server" Value="0" />
            <asp:HiddenField ID="FxDialogStyle" runat="server" Value="0" />
            <asp:HiddenField ID="BusinessDialogStyle" runat="server" Value="0" />
            <asp:HiddenField ID="NormalScreenStyle" runat="server" Value="0" />
            <asp:HiddenField ID="NormalScreenTarget" runat="server" Value="0" />
            <asp:HiddenField ID="DialogFrameUrl" runat="server" Value="0" />
            <asp:HiddenField ID="WindowGuid" runat="server" Value="0" />
            <asp:HiddenField ID="RequestTicketGuid" runat="server" Value="0" />
            <!--FxCode:add-end-->
    
        </form>
    </body>
    </html>
  4. Save TouryoMaster.master.

    Note:
    If master page is not saved at this step, an error occurs in Visual Studio designer when creating web forms in the subsequent steps.

4.2.2 Create orders list form

  1. In Solution Explorer, select Aspx\sample folder. Click Project -> Add New Item in toolbar.

  2. Select Web Form with Master Page and add new web form named OrdersList.aspx.

  3. In Select a Master Page dialog, select Aspx\Common\TouryoMaster.master and click OK.

  4. Add GridView control to OrdersList.aspx, and set the ID property to gvwOrdersList.

    Note:
    If the prefix of control name, e.g. "gvw", is set incorrectly, the control is not recognized correctly by Open Touryo. For details, refer Open Touryo user guide (Leader edition).

  5. Click Edit Columns in GridView Tasks menu.

  6. Select ButtonField in Available fields list and click Add.

  7. Set the properties of ButtonField as follows:

    • ButtonType: Button
    • Text: Select
    • Leave the other fields as default.
  8. Confirm that Select buttons have been added to GridView.

4.2.3 Create order details form

  1. In the same way to section 4.2.2, create a web form that displays the order details. Here, name the form OrderDetails.aspx.

  2. Add two Label controls, two GridView controls and Button control to OrderDetails.aspx as following image.

    Set it as below respectively.

    • Label (Upper part)
      • Text: Order information (Summary)
    • Label (Lower part)
      • Text: Order information (Details)
    • GridView (Upper part)
      • ID: gvwOrderSummary
      • AutoGenerateEditButton: true
    • GridView (Lower part)
      • ID: gvwOrderDetails
      • AutoGenerateEditButton: true
    • Button
      • Name: btnUpdateOrder
      • Text: Update order Information

4.2.4 Configure PDF file that displays in dialog window

  1. In Solution Explorer, select Aspx\sample folder. Click Project -> Add Existing Item in toolbar.

  2. In Add Existing Item dialog, select C:\root\files\resource\Test\test.pdf and click Add.

  3. Confirm that test.pdf file has been add to Aspx\sample folder.

4.2.5 Modify menu screen

  1. In Solution Explorer, open Aspx\start\menu.aspx.

  2. Insert the following code to add the LinkButton(ID: lbnGetOrdersList) for transferring to orders list form and the LinkButton(ID: lbnShowDialog) for displaying the dialog window.

    ・ Tutorial<br />
      -  
    <asp:LinkButton ID="lbnGetOrdersList" runat="server">Get order information list</asp:LinkButton>
    <br />
      -  
    <asp:LinkButton ID="lbnShowDialog" runat="server">Display modal dialog</asp:LinkButton>
  3. Confirm that added LinkButtons are shown in the design view of menu.aspx.

4.3 Configure screen transition

4.3.1 Configure application configuration file (app.config)

  1. In Solution Explorer, open app.config.

  2. Set FxScreenTransitionMode to R.

    <!-- 画面遷移方法を指定(T:Transfer、R:Redirect、off) -->
    <add key="FxScreenTransitionMode" value="R"/>

4.3.2 Configure screen transition definition file (SCDefinition.xml)

Define screen transition in SCDefinition.xml file when controlling screen transition with Open Touryo.

  1. Open C:\root\files\resource\Xml\SCDefinition.xml with Notepad.

  2. Modify the definition of menu.aspx as follows:

    <Screen value="/ProjectX_sample/Aspx/start/menu.aspx" directLink="allow">
        <!-- Define transition to orders list form -->
        <Transition value="/ProjectX_sample/Aspx/sample/OrdersList.aspx" label="List"/>
    </Screen>
  3. Define orders list form and order details form in SCDefinition.xml.

    <!-- Orders list form -->
    <Screen value="/ProjectX_sample/Aspx/sample/OrdersList.aspx" directLink="deny">
        <!-- Define transition to order details form -->
        <Transition value="/ProjectX_sample/Aspx/sample/OrderDetails.aspx" label="Detail"/>
    </Screen>
    
    <!-- Order details form -->
    <Screen value="/ProjectX_sample/Aspx/sample/OrderDetail.aspx" directLink="deny">
    </Screen>

    Note:
    Refer to Open Touryo user guide (Each Function Edition) for information about the notation of SCDefinition.xml and the details of screen definition with Open Touryo.

4.4 Create Parmeter and Return value class

4.4.1 Create Parameter Value class

  1. In Solution Explorer, select AppCode\sample\Common folder. Click Project -> Add Class in toolbar.

  2. Add new class named OrderParameterValue.vb.

  3. Add the following namespaces in OrderParameterValue.vb to import the classes provided by Open Touryo.

    Imports Touryo.Infrastructure.Business.Util
    Imports Touryo.Infrastructure.Business.Common
  4. Inherit Parameter Value Parent Class of Open Touryo to OrderParameterValue class as shown below.

    Public Class OrderParameterValue
        Inherits MyParameterValue
  5. Create OrderParameterValue constructor with the following code.

    Public Sub New(screenId As String, controlId As String, methodName As String, actionType As String, user As MyUserInfo)
        MyBase.New(screenId, controlId, methodName, actionType, user)
    End Sub
  6. Create the following properties in OrderParameterValue class to transfer data from form to data access class.

    ''' <summary>Order ID</summary>
    Public OrderId As String
    
    ''' <summary>Order information (Summary)</summary>
    Public Orders As System.Data.DataTable
    
    ''' <summary>Order information (Details)</summary>
    Public OrderDetails As System.Data.DataTable

4.4.2 Create Return Value class

  1. In the same way to section 4.4.1, create new class named OrderReturnValue.vb.

  2. Add the following namespace in OrderReturnValue.vb to import the classes provided by Open Touryo.

    Imports Touryo.Infrastructure.Business.Common
  3. Inherit the Return Value Parent Class of Open Touryo to OrderReturnValue class as shown below.

    Public Class OrderReturnValue
        Inherits MyReturnValue
  4. Create the following properties in OrderReturnValue class to transfer the resultant data from data access class to form.

    ''' <summary>Order information (Summary)</summary>
    Public Orders As System.Data.DataTable
    
    ''' <summary>Order information (Details)</summary>
    Public OrderDetails As System.Data.DataTable

4.5 Create data access class

4.5.1 Generate data access class and SQL files

Perform the following steps to generate data access class and SQL files that implement simple CRUD operation for table or view, using the D layer auto generation tool (DaoGen_Tool) bundled with Open Touryo template base.

  1. Open C:\root\programs\C#\Frameworks\DaoGen_Tool\bin\Debug\DaoGen_Tool.exe.

  2. In the STEP1 screen, set database information as follows and click acquisition.

    • Data provider: SQL Server Client
    • Connection string: Data Source=localhost\SQLExpress;Initial Catalog=Northwind;Integrated Security=true;
    • Schema Info: Summary Information
  3. If database information, such as connection string, are correct, Display (Summary Information) dialog of schema information of DBMS screen is shown.

    Click Close to close the dialog box.

  4. Click Get Table List.

    In the Note? (prerequisites) dialog box, click OK.

  5. Tables and views in Northwind database are shown in list box. Since Orders table and Order Details table will be used in this tutorial, select all tables and views except Order table and Order Details table, and click Delete.

  6. Confirm whether Table List contains only Order table and Order Details table, and click Load.

  7. The Generate D layer definition file button is activated. Select utf-8 as file encoding and click Generate D layer definition file.

    Save as C:\root\Info.csv.

  8. Click OK in the dialog box displaying the message Completion of generation of the D-layer definition information!.

  9. Click Go to STEP 2.

  10. In the STEP2 screen, enter input / output settings as follows:

    • Language: VB
    • D layer definition file: C:\root\Info.csv
    • Source Template Folder: C:\root\files\tools\DGenTemplates
    • Output File: C:\root
    • Leave the other fields as default.

    Click Generate Program.

  11. Click OK in the dialog box displaying the message Automatic Generation Completed!.

  12. Confirm that data access classes and SQL files are generated in C:\root folder.

    Note:
    In the Open Touryo framework, the files with extensions .sql and .xml are SQL files. (For more details, refer to the Open Touryo framework user guide)

  13. To add generated data access class to sample program, select Dao folder in Solution Explorer, and click Project -> Add Existing File in toolbar.

  14. In the Add Existing Item screen, select DaoOrders.vb and DaoOrder_Details.vb in C:\root folder. Click Add.

  15. Copy the generated SQL and XML files in C:\root to C:\root\files\resource\Sql folder.

  16. Close D layer auto generation tool.

4.5.2 Create SQL file for the List of Orders

D layer auto generation tool can generate data access class and SQL file for simple CRUD processing. However, the developer should create sql file individually for complicated processing, such as join multiple tables.

  1. Create SelectOrders.sql file in C:\root\files\resource\Sql folder.

  2. Add the following SQL scripts in SelectOrders.sql to get the list of orders.

    SELECT
        Orders.OrderID, Customers.CompanyName, Customers.ContactName, Employees.LastName As EmployeeLastName, Employees.FirstName As EmployeeFirstName, Orders.OrderDate
    FROM
        Orders
            INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
            INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID

4.5.3 Create Dao Summary Class

In this tutorial, the following data access classes are used.

  • DaoOrders
    • For access to Orders table
  • DaoOrder_Details
    • For access to Order Details table
  • CmnDao (Common data access class with Open Touryo)
    • For access with SQL file created in section 4.5.2.

In this section describes how to create Dao Summary Class. Dao summary Class is Facade for business logic class, and controls the call the above data access classes.

  1. Select Dao folder in the Solution Explorer. And click Project -> Add Class in toolbar.

  2. Add class named ConsolidatedLayerD.vb.

  3. Add the following namespaces to ConsolidatedLayerD.vb to import the classes provided by Open Touryo, and parameter and return value class created in section 4.4.

    ' Open Touryo
    Imports Touryo.Infrastructure.Business.Dao
    Imports Touryo.Infrastructure.Public.Db
    
    ' Parameter and return value class
    Imports ProjectX_sample.AppCode.sample.Common
  4. Inherit Data Access Parent Class of Open Touryo framework to ConsolidatedLayerD class as shown below.

    Public Class ConsolidatedLayerD
        Inherits BaseConsolidateDao
  5. Create ConsolidatedLayerD constructor with the following code.

    Public Sub New(dam As BaseDam)
        MyBase.New(dam)
    End Sub
  6. Create GetOrders method to get the list of orders with the following code.

    Public Function GetOrders(orderParameter As OrderParameterValue) As OrderReturnValue
        ' Create an object of Return Value class
        Dim returnValue As New OrderReturnValue()
    
        ' Create an object of common DAO and assign SQL file
        Dim dao As New CmnDao(Me.Dam)
        dao.SQLFileName = "SelectOrders.sql"
    
        ' Create an object of DataTable
        Dim table As New System.Data.DataTable()
    
        ' Get the list of orders information from the database and stored in a DataTable
        dao.ExecSelectFill_DT(table)
    
        ' Store the orders information to the Return Value class and return to the B layer
        returnValue.Orders = table
        Return returnValue
    End Function
  7. Create GetOrderById method to get the details of specific order summary and order details information based on the Order ID with the following code.

    Public Function GetOrderById(orderParameter As OrderParameterValue) As OrderReturnValue
        ' Create an object of Return Value class
        Dim returnValue As New OrderReturnValue()
    
        ' Create an object of auto generated DAO classes
        Dim orderDao As New DaoOrders(Me.Dam)
        Dim orderDetailsDao As New DaoOrder_Details(Me.Dam)
    
        ' Create objects of DataTable to store the details of specified order information
        Dim orderTable As New System.Data.DataTable()
        Dim orderDetailsTable As New System.Data.DataTable()
    
        ' Set the required parameters
        orderDao.PK_OrderID = orderParameter.OrderId
        orderDetailsDao.PK_OrderID = orderParameter.OrderId
    
        ' Get the details of specific order information from the database and stored in the DataTable
        orderDao.D2_Select(orderTable)
        orderDetailsDao.D2_Select(orderDetailsTable)
    
        ' Store the details of specific order information to the Return Value class and return to the B layer
        returnValue.Orders = orderTable
        returnValue.OrderDetails = orderDetailsTable
        Return returnValue
    End Function
  8. Create UpdateOrder method to update the details of specified order summary and order details information with the following code.

    Public Function UpdateOrder(orderParameter As OrderParameterValue) As OrderReturnValue
        ' Create an object of Return Value class
        Dim returnValue As New OrderReturnValue()
    
        ' Create an object of auto generated DAO classes
        Dim orderDao As New DaoOrders(Me.Dam)
        Dim orderDetailsDao As New DaoOrder_Details(Me.Dam)
    
        ' Create an object of DataTable to store order information and order details information
        Dim orderTable As System.Data.DataTable = orderParameter.Orders
        Dim orderDetailsTable As System.Data.DataTable = orderParameter.OrderDetails
    
        ' Judge the state of DataRow, and update database if DataRow is modified
        If orderTable.Rows(0).RowState = System.Data.DataRowState.Modified Then
            ' 注文情報(サマリ)更新用のパタメータを設定する
            orderDao.PK_OrderID = orderTable.Rows(0)("OrderId")
            orderDao.Set_OrderDate_forUPD = orderTable.Rows(0)("OrderDate")
            orderDao.Set_RequiredDate_forUPD = orderTable.Rows(0)("RequiredDate")
            orderDao.Set_ShippedDate_forUPD = orderTable.Rows(0)("ShippedDate")
            orderDao.Set_ShipVia_forUPD = orderTable.Rows(0)("ShipVia")
            orderDao.Set_Freight_forUPD = orderTable.Rows(0)("Freight")
            orderDao.Set_ShipName_forUPD = orderTable.Rows(0)("ShipName")
            orderDao.Set_ShipAddress_forUPD = orderTable.Rows(0)("ShipAddress")
            orderDao.Set_ShipCity_forUPD = orderTable.Rows(0)("ShipCity")
            orderDao.Set_ShipRegion_forUPD = orderTable.Rows(0)("ShipRegion")
            orderDao.Set_ShipPostalCode_forUPD = orderTable.Rows(0)("ShipPostalCode")
            orderDao.Set_ShipCountry_forUPD = orderTable.Rows(0)("ShipCountry")
    
            ' Update the order information to the database
            orderDao.D3_Update()
        End If
    
        For Each row As System.Data.DataRow In orderDetailsTable.Rows
            ' Judge the state of DataRow, and update database if DataRow is modified
            If row.RowState = System.Data.DataRowState.Modified Then
                ' Set the parameters of the order details information
                orderDetailsDao.PK_OrderID = row("OrderId")
                orderDetailsDao.PK_ProductID = row("ProductId")
                orderDetailsDao.Set_UnitPrice_forUPD = row("UnitPrice")
                orderDetailsDao.Set_Quantity_forUPD = row("Quantity")
                orderDetailsDao.Set_Discount_forUPD = row("Discount")
    
                ' Update the order details information to the database
                orderDetailsDao.D3_Update()
            End If
        Next
        ' Return result value
        Return returnValue
    End Function

4.6 Create business logic class

  1. In Solution Explorer, select AppCode\sample\Business folder. Click Project -> Add Class in toolbar.

  2. Add class named OrdersLogic.vb.

  3. Add the following namespaces to OrdersLogic.vb to import the classes provided by Open Touryo, and parameter and return value class, and data access class.

    ' Open Touryo
    ' Business
    Imports Touryo.Infrastructure.Business.Business
    Imports Touryo.Infrastructure.Business.Common
    Imports Touryo.Infrastructure.Business.Dao
    Imports Touryo.Infrastructure.Business.Exceptions
    Imports Touryo.Infrastructure.Business.Presentation
    Imports Touryo.Infrastructure.Business.Util
    
    ' Framework
    Imports Touryo.Infrastructure.Framework.Business
    Imports Touryo.Infrastructure.Framework.Common
    Imports Touryo.Infrastructure.Framework.Dao
    Imports Touryo.Infrastructure.Framework.Exceptions
    Imports Touryo.Infrastructure.Framework.Presentation
    Imports Touryo.Infrastructure.Framework.Util
    Imports Touryo.Infrastructure.Framework.Transmission
    
    ' Public
    Imports Touryo.Infrastructure.Public.Db
    Imports Touryo.Infrastructure.Public.IO
    Imports Touryo.Infrastructure.Public.Log
    Imports Touryo.Infrastructure.Public.Str
    Imports Touryo.Infrastructure.Public.Util
    
    ' Parameter and Return value class
    Imports ProjectX_sample.AppCode.sample.Common
    
    ' Data access class
    Imports ProjectX_sample.AppCode.sample.Dao
  4. Inherit Business Parent Class of Open Touryo framework to OrdersLogic class as shown below.

    Public Class OrdersLogic
        Inherits MyFcBaseLogic
  5. Create UOC_GetOrders method to get the list of orders with the following code.

    Private Sub UOC_GetOrders(orderParameter As OrderParameterValue)
        '    Create an object DAO Summary class
        Dim facade As New ConsolidatedLayerD(Me.GetDam())
    
        ' Get the list of orders information
        Dim returnValue As OrderReturnValue = facade.GetOrders(orderParameter)
    
        ' Return the object of Return Value class
        Me.ReturnValue = returnValue
    End Sub

    Note:
    The method to be called from the Controller class is required to be created as UOC_xx (xx is arbitrary string). When controller sends xx as parameter, Open Touryo framework allocates the processing to UOC_xx method in business logic class.

  6. Create UOC_GetOrderById method to get the details of specific order summary and order details information based on the Order ID with the following code.

    Private Sub UOC_GetOrderById(orderParameter As OrderParameterValue)
        ' Create an object DAO Summary class
        Dim facade As New ConsolidatedLayerD(Me.GetDam())
    
        ' Get the details of specific order information and order details information based on Order ID
        Dim returnValue As OrderReturnValue = facade.GetOrderById(orderParameter)
    
        ' Return the object of Return Value class
        Me.ReturnValue = returnValue
    End Sub
  7. Create UOC_UpdateOrder method to update the details of specified order summary and order details information with the following code.

    Private Sub UOC_UpdateOrder(orderParameter As OrderParameterValue)
        ' Create an object DAO Summary class
        Dim facade As New ConsolidatedLayerD(Me.GetDam())
    
        ' Update the specified order information and order details information
        Dim returnValue As OrderReturnValue = facade.UpdateOrder(orderParameter)
    
        ' Return the object of Return Value class
        Me.ReturnValue = returnValue
    End Sub

4.7 Implement code behind

4.7.1 Implement code behind of master page

  1. In Solution Explorer, open Aspx\Common\TouryoMaster.master.vb.

  2. Add the following namespaces to OrdersForm.vb to import the namespaces of Open Touryo.

    Imports Touryo.Infrastructure.Framework.Presentation
  3. Inherit Master Page Parent Class of Open Touryo to TouryoMaster class as shown below.

    Public Partial Class Aspx_Common_TouryoMaster
        Inherits BaseMasterController

    Note:
    Open Touryo provides the utility method for acquiring the controls in master page or contents page. If master page does not inherit Master Page Parent Class, this utility method can not acquire controls normally. Therefore, when using this utility method, master page should inherit Master Page Parent Class. For more details, refer to Open Touryo user guide (Leader Edition).

4.7.2 Implement code behind of menu screen

  1. In Solution Explorer, open Aspx\start\menu.aspx.vb.

  2. Add handler method to menu.aspx.vb for Click event of LinkButton that was added at section 4.2.5.

    Protected Function UOC_lbnGetOrdersList_Click(eventArgs As FxEventArgs) As String
        ' Transfer screen according to the value defined in SCDefinitions.xml
        Return "List"
    End Function
    
    Protected Function UOC_lbnShowDialog_Click(eventArgs As FxEventArgs) As String
        ' Show modal dialog
        Me.ShowNormalScreen("/ProjectX_sample/Aspx/sample/test.pdf")
    
        ' Return empty string
        Return String.Empty
    End Function

    Note:
    When using Open Touryo, event handers of the controls, e.g. Button, should be named UOC_[Control Name]_[Event Name]. For more details, refer to Open Touryo user guide (Common Edition).

4.7.3 Implement code behind of order list form

  1. In Solution Explorer, open Aspx\sample\OrdersList.aspx.vb.

  2. Add the following namespaces to OrdersList.aspx.vb to import the classes provided by Open Touryo, and parameter and return value class and business logic class.

    ' Open Touryo
    ' Business
    Imports Touryo.Infrastructure.Business.Business
    Imports Touryo.Infrastructure.Business.Common
    Imports Touryo.Infrastructure.Business.Dao
    Imports Touryo.Infrastructure.Business.Exceptions
    Imports Touryo.Infrastructure.Business.Presentation
    Imports Touryo.Infrastructure.Business.Util
    
    ' Framework
    Imports Touryo.Infrastructure.Framework.Business
    Imports Touryo.Infrastructure.Framework.Common
    Imports Touryo.Infrastructure.Framework.Dao
    Imports Touryo.Infrastructure.Framework.Exceptions
    Imports Touryo.Infrastructure.Framework.Presentation
    Imports Touryo.Infrastructure.Framework.Util
    Imports Touryo.Infrastructure.Framework.Transmission
    
    ' Public
    Imports Touryo.Infrastructure.Public.Db
    Imports Touryo.Infrastructure.Public.IO
    Imports Touryo.Infrastructure.Public.Log
    Imports Touryo.Infrastructure.Public.Str
    Imports Touryo.Infrastructure.Public.Util
    
    ' Parameter and return value class
    Imports ProjectX_sample.AppCode.sample.Common
    
    ' Business logic class
    Imports ProjectX_sample.AppCode.sample.Business
  3. Inherit Screen Parent Class of Open Touryo to OrdersList class as shown below.

    Public Partial Class Aspx_sample_OrdersList
        Inherits MyBaseController
  4. Click light bulbs and select Implement Abstract Class.

  5. Remove auto-generated Page_Load method.

  6. Override UOC_FormInit method to display the order information list during the form load with the following code. Because no processing should be executed in post back, empty UOC_FormInit_PostBack method.

    Protected Overrides Sub UOC_FormInit()
        ' Create parameter class
        ' (Send "GetOrders" as parameter to call UOC_GetOrders in business logic class)
        Dim param As New OrderParameterValue(Me.ContentPageFileNoEx, "", "GetOrders", "SQL", Me.UserInfo)
    
        ' Create return value class
        Dim returnValue As OrderReturnValue
    
        ' Call business logic class
        Dim logic As new OrdersLogic()
        returnValue = DirectCast(logic.DoBusinessLogic(param), OrderReturnValue)
    
        ' Display the result in gridview
        Me.gvwOrdersList.DataSource = returnValue.Orders
        Me.gvwOrdersList.DataBind()
    End Sub
    
    Protected Overrides Sub UOC_FormInit_PostBack()
    End Sub
  7. Add a method to OrdersList.aspx.vb for transitioning to order details form when clicking the button in each rows of gridview.

    Protected Function UOC_gvwOrdersList_RowCommand(eventArgs As FxEventArgs) As String
        ' Get index of selected row
        Dim RowIndex As Integer = Integer.Parse(eventArgs.PostBackValue)
    
        ' Get Order Id of selected row
        Dim orderId As String = Me.gvwOrdersList.Rows(RowIndex).Cells(1).Text
    
        ' Store Order Id in session
        Session("OrderId") = OrderId
    
        ' Transfer screen according to the label defined in SCDefinitions.xml
        Return "Detail"
    End Function

4.7.4 Implement code behind of order detail form

  1. In Solution Explorer, open Aspx\sample\OrderDetails.aspx.vb.

  2. In the same way to section 4.7.3, inherit Screen Parent Class of Open Touryo to OrderDetails class.

  3. Remove auto-generated Page_Load method.

  4. Override UOC_FormInit method to display the order details information during the form load with the following code. Because no processing should be executed in post back, empty UOC_FormInit_PostBack method.

    Protected Overrides Sub UOC_FormInit()
        ' Get Order Id from session
        Dim OrderId As String = Session("OrderId").ToString()
    
        ' Create parameter class
        ' (Send "GetOrderById" as parameter to call UOC_GetOrderById in business logic class)
        Dim param As New OrderParameterValue(Me.ContentPageFileNoEx, "", "GetOrderById", "SQL", Me.UserInfo)
    
        ' Send order id for search criteria
        param.OrderId = OrderId
    
        ' Create return value class
        Dim returnValue As OrderReturnValue
    
        ' Call business logic class
        Dim logic As New OrdersLogic()
        returnValue = DirectCast(logic.DoBusinessLogic(param), OrderReturnValue)
    
        ' Store order information in session
        Session("Orders") = returnValue.Orders
        Session("OrderDetails") = returnValue.OrderDetails
    
        ' Display result in gridview
        Me.gvwOrderSummary.DataSource = returnValue.Orders
        Me.gvwOrderSummary.DataBind()
        Me.gvwOrderDetails.DataSource = returnValue.OrderDetails
        Me.gvwOrderDetails.DataBind()
    End Sub
    
    Protected Overrides Sub UOC_FormInit_PostBack()
    End Sub
  5. In Solution Explorer, open Aspx\sample\OrderDetails.aspx.

  6. Select gvwOrderSummary control and click event icon in the property window.

  7. Double click RowEditing event and RowCancelingEdit event in event list.

  8. Since gvwOrderSummary_RowEditing method and gvwOrderSummary_RowCancelingEdit method have been generated in OrderDetails.aspx.vb, implement as follows:

    Protected Sub gvwOrderSummary_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvwOrderSummary.RowEditing
        ' Switch gvwOrderSummary to edit mode
        Me.gvwOrderSummary.EditIndex = e.NewEditIndex
        Me.gvwOrderSummary.DataSource = DirectCast(Session("Orders"), System.Data.DataTable)
        Me.gvwOrderSummary.DataBind()
    
        ' Set primary key and foreign key columns as read only
        DirectCast(Me.gvwOrderSummary.Rows(e.NewEditIndex).Cells(1).Controls(0), TextBox).Enabled = False
        DirectCast(Me.gvwOrderSummary.Rows(e.NewEditIndex).Cells(2).Controls(0), TextBox).Enabled = False
        DirectCast(Me.gvwOrderSummary.Rows(e.NewEditIndex).Cells(3).Controls(0), TextBox).Enabled = False
    End Sub
    
    Protected Sub gvwOrderSummary_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvwOrderSummary.RowCancelingEdit
        ' Switch gvwOrderSummary to display mode
        Me.gvwOrderSummary.EditIndex = -1
        Me.gvwOrderSummary.DataSource = DirectCast(Session("Orders"), System.Data.DataTable)
        Me.gvwOrderSummary.DataBind()
    End Sub

    Note:
    Event handling feature of Open Touryo does not support RowEditing event and RowCancelingEdit event of GridView. Therefore, to handle these events, event handling feature of .NET Framework should be used. So, the flow control feature, e.g. pre-process of event hander or post-process of event hander or error handler, can not be used. If using the flow control feature for these events, customize Screen Parent Class. For more details, refer to Open Touryo user guide (Common Edition).

  9. Add a method to OrderDetails.aspx.vb for saving the changes of order information (summary).

    Protected Function UOC_gvwOrderSummary_RowUpdating(eventArgs As FxEventArgs, e As GridViewUpdateEventArgs) As String
        ' Save the changes of order information (summary)
        Dim orders As System.Data.DataTable = DirectCast(Session("Orders"), System.Data.DataTable)
        For Each key As String In e.NewValues.Keys
                Orders.Rows(0)(key) = e.NewValues(key)
        Next
    
        ' Switch gvwOrderSummary to display mode
        Me.gvwOrderSummary.EditIndex = -1
        Me.gvwOrderSummary.DataSource = DirectCast(Session("Orders"), System.Data.DataTable)
        Me.gvwOrderSummary.DataBind()
    
        ' Return empty string (Don't need screen transition)
        Return String.Empty
    End Function
  10. In the same way, add RowEditing event handler, RowCancelingEdit event handler, UOC_gvwOrderDetails_RowUpdating methods to gvwOrderDetails control. Implement as follows:

    Protected Sub gvwOrderDetails_RowEditing(sender As object, e As GridViewEditEventArgs)
        ' Switch order information (Details) to edit mode
        Me.gvwOrderDetails.EditIndex = e.NewEditIndex
        Me.gvwOrderDetails.DataSource = DirectCast(Session("OrderDetails"), System.Data.DataTable)
        Me.gvwOrderDetails.DataBind()
    
        ' Set primary key and foreign key read only
        DirectCast(Me.gvwOrderDetails.Rows(e.NewEditIndex).Cells(1).Controls(0),TextBox).Enabled = false
        DirectCast(Me.gvwOrderDetails.Rows(e.NewEditIndex).Cells(2).Controls(0),TextBox).Enabled = false
    End Sub
    
    Protected Sub gvwOrderDetails_RowCancelingEdit(sender As Object sender, e As GridViewCancelEditEventArgs)
        ' Switch order information (details) to display mode
        Me.gvwOrderDetails.EditIndex = -1
        Me.gvwOrderDetails.DataSource = DirectCast(Session("OrderDetails"), System.Data.DataTable)
        Me.gvwOrderDetails.DataBind()
    End Sub
    
    Protected Function UOC_gvwOrderDetails_RowUpdating(eventArgs As FxEventArgs, e As GridViewUpdateEventArgs) As String
        ' Save the changes of order information (details)
        Dim OrderDetails As System.Data.DataTable = DirectCast(Session("OrderDetails"), System.Data.DataTable)
        For Each key As String In e.NewValues.Keys
            OrderDetails.Rows(e.RowIndex)(key) = e.NewValues(key)
        Next
    
        ' Switch order infroamtion (details) to display mode
        Me.gvwOrderDetails.EditIndex = -1
        Me.gvwOrderDetails.DataSource = DirectCast(Session("OrderDetails"), System.Data.DataTable)
        Me.gvwOrderDetails.DataBind()
    
        ' Return empty string (Don't need screen transition)
        Return String.Empty
    End Function
  11. Add a method for reflecting the changes on database.

    Protected Function UOC_btnUpdateOrder_Click(eventArgs As FxEventArgs) As String
        ' Get the value of gridview from session
        Dim orderTable As System.Data.DataTable = DirectCast(Session("Orders"), System.Data.DataTable)
        Dim orderDetailTable As System.Data.DataTable = DirectCast(Session("OrderDetails"), System.Data.DataTable)
    
        ' Create parameter value class
        rParameterValue(Me.Title, "", "UpdateOrder", "SQL", Me.UserInfo)
    
        ' Send the value of gridview to business logic class
        param.Orders = orderTable
        param.OrderDetails = orderDetailTable
    
        ' Create return value class
        Dim returnValue As OrderReturnValue
    
        ' Call business logic class
        Dim logic As New OrdersLogic()
        returnValue = DirectCast(logic.DoBusinessLogic(param), OrderReturnValue)
    
        ' Return empty string (Don't need screen transition)
        Return String.Empty
    End Function

4.8 Confirm the setting information

4.8.1 Confirm the setting of application configuration file (Web.config)

  1. In the Solution Explorer, open web.config.

  2. Check connectionStrings section, and confirm that the connection string is correct.

    <connectionStrings>
        <!-- SQL Server / SQL Client用 -->
        <add name="ConnectionString_SQL" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=Northwind;Integrated Security=True;"/>
    </connectionStrings>

4.9 Check operations

4.9.1 Start ASP.NET state service

  1. Run services.msc in the Search programs and files box on the start menu.

  2. In Services window, right-click ASP.NET state service and select Start.

  3. Confirm that the status of ASP.NET state services has been changed to Started.

4.9.2 Confiture intranet security

  1. Run inetcpl.cpl in the Search programs and files box on the start menu.

  2. Select Security tab in Internet Properties dialog. And, select Local intranet and click Sites.

  3. In Local intranet dialog, set the properties as follows and click OK.

    • Automatically detect intranet network: uncheck
    • Other than the above: check
  4. Click OK to close Internet Properties dialog.

4.9.3 Debug the sample application

  1. In Solution Explorer, right-click Aspx\start\menu.aspx and select Set As Start Page.

  2. Debug the sample application with Visual Studio.

  3. Since the browser is launched and login form is shown, input the value as follows and click ログイン (Login in Japanese).

  4. Since menu screen is shown, click Get order information list.

  5. Confirm that orders are displayed and click Select in any row.

  6. Confirm that order detail is displayed and click Edit in the row that will be modified.

  7. Since the clicked row is switched to Edit mode, edit the value in the row. When completing editing, click Update to save the changes.

  8. Click Update order Information to reflect the changes on database.

  9. Execute the following command and confirm that database is updated successfully. In the following command, replace order number (OrderId) that has been selected in previous step from [Selected order no.].

    "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S localhost\SQLExpress -E -d Northwind -Q "Select * From Orders Inner Join [Order Details] On Orders.OrderId=[Order Details].OrderId Where Orders.OrderId=[Selected order no.]"
  10. Click メニュー画面 to back to menu screen.

  11. Click Display modal dialog.

  12. Confirm that pdf file is displayed in dialog and close dialog.

  13. Move to http://localhost:9999/ProjectX_sample/Aspx/sample/OrdersList.aspx with browser.

  14. Confirm that the error message of Open Touryo is shown.

    Note:
    This error message shows that the screen transition to OrdersList.aspx with GET method is not permitted. This is because directLink property of orders list form and order details form is set to deny in SCDefinitions.xml in section 4.3.2.

4.9.4 Confirm trace log

  1. Open log file - C:\root\files\resource\Log\ACCESS.yyyy-mm-dd.log (where, yyyy-mm-dd is executed date) in Notepad.

  2. Confirm that the access to OrderList and OrderDetails is logged.

    [2017/04/06 11:24:54,043],[INFO ],[9],Splash
    [2017/04/06 11:24:54,058],[INFO ],[10],Splash
    [2017/04/06 11:24:57,084],[INFO ],[9],,-,-,Login,Form_Load
    [2017/04/06 11:25:00,060],[INFO ],[9],,-,----->,Login,btnButton1
    [2017/04/06 11:25:00,065],[INFO ],[9],,user01,-,Login,Form_Closed
    [2017/04/06 11:25:00,076],[INFO ],[9],,user01,<-----,Login,btnButton1,16,0
    [2017/04/06 11:25:00,099],[INFO ],[9],,user01,-,OrdersForm,Form_Load
    [2017/04/06 11:25:00,667],[INFO ],[9],,user01,xxx,----->>,OrdersForm,,GetOrders,
    [2017/04/06 11:25:03,008],[INFO ],[9],,user01,xxx,<<-----,OrdersForm,,GetOrders,,2341,203
    [2017/04/06 11:28:46,964],[INFO ],[9],,user01,----->,OrdersForm,btnShowOrderDetail
    [2017/04/06 11:28:46,983],[INFO ],[9],,user01,-,OrderDetailsForm,Form_Load
    [2017/04/06 11:28:46,986],[INFO ],[9],,user01,xxx,----->>,OrderDetailsForm,,GetOrderById,
    [2017/04/06 11:28:49,486],[INFO ],[9],,user01,xxx,<<-----,OrderDetailsForm,,GetOrderById,,2501,31
    [2017/04/06 11:28:49,537],[INFO ],[9],,user01,<-----,OrdersForm,btnShowOrderDetail,2573,109
    [2017/04/06 11:36:09,282],[INFO ],[9],,user01,----->,OrderDetailsForm,btnUpdateOrder
    [2017/04/06 11:36:09,456],[INFO ],[9],,user01,xxx,----->>,OrderDetailsForm,,UpdateOrder,
    [2017/04/06 11:36:10,000],[INFO ],[9],,user01,xxx,<<-----,OrderDetailsForm,,UpdateOrder,,543,47
    [2017/04/06 11:39:11,799],[INFO ],[9],,user01,<-----,OrderDetailsForm,btnUpdateOrder,182512,125
    [2017/04/06 11:39:13,542],[INFO ],[9],,user01,-,OrderDetailsForm,Form_Closed
    [2017/04/06 11:39:15,232],[INFO ],[9],,user01,-,OrdersForm,Form_Closed
  3. Open log file - C:\root\files\resource\Log\SQLTRACE.yyyy-mm-dd.log (where, yyyy-mm-dd is executed date) in Notepad.

  4. Confirm the executed SQL text for Orders and OrderDetails table with the following SQL trace log.

    [2017/04/06 11:25:03,006],[INFO ],[9],207,16,[commandText]:SELECT Orders.OrderID, Customers.CompanyName, Customers.ContactName, Employees.LastName As EmployeeLastName, Employees.FirstName As EmployeeFirstName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID    [commandParameter]:
    [2017/04/06 11:28:49,335],[INFO ],[9],51,16,[commandText]: -- DaoOrders_D2_Select -- 2012/7/30 日立 太郎 SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate], [RequiredDate], [ShippedDate], [ShipVia], [Freight], [ShipName], [ShipAddress], [ShipCity], [ShipRegion], [ShipPostalCode], [ShipCountry] FROM [Orders] WHERE [OrderID] = @OrderID    [commandParameter]:OrderID=10248,
    [2017/04/06 11:28:49,486],[INFO ],[9],150,0,[commandText]: -- DaoOrder_Details_D2_Select -- 2012/7/30 日立 太郎 SELECT [OrderID], [ProductID], [UnitPrice], [Quantity], [Discount] FROM [Order Details] WHERE [OrderID] = @OrderID    [commandParameter]:OrderID=10248,
Clone this wiki locally