Skip to content

Tutorial_ASPNET_CSharp

daisuke nishino edited this page Oct 17, 2018 · 3 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
      • C#
    • 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\WebForms_Sample\WebForms_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.cs" Inherits="WebForms_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="/WebForms_Sample/Aspx/start/menu.aspx" directLink="allow">
        <!-- Define transition to orders list form -->
        <Transition value="/WebForms_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="/WebForms_Sample/Aspx/sample/OrdersList.aspx" directLink="deny">
        <!-- Define transition to order details form -->
        <Transition value="/WebForms_Sample/Aspx/sample/OrderDetails.aspx" label="Detail"/>
    </Screen>
    
    <!-- Order details form -->
    <Screen value="/WebForms_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.cs.

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

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

    public class OrderParameterValue : MyParameterValue
  5. Create OrderParameterValue constructor with the following code.

    public OrderParameterValue(string screenId, string controlId, string methodName, string actionType, MyUserInfo user) : base(screenId, controlId, methodName, actionType, user)
    {
    }
  6. Create the following properties in OrderParameterValue class to transfer data from form to data access class.

    /// <summary>Order ID</summary>
    public string OrderId;
    
    /// <summary>Order information (Summary)</summary>
    public System.Data.DataTable Orders;
    
    /// <summary>Order information (Details)</summary>
    public System.Data.DataTable OrderDetails;

4.4.2 Create Return Value class

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

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

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

    public class OrderReturnValue : 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 System.Data.DataTable Orders;
    
    /// <summary>Order information (Details)</summary>
    public System.Data.DataTable OrderDetails;

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:

    • 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.cs and DaoOrder_Details.cs 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.cs.

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

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

    public class ConsolidatedLayerD : BaseConsolidateDao
  5. Create ConsolidatedLayerD constructor with the following code.

    public ConsolidatedLayerD(BaseDam dam) : base(dam) { }
  6. Create GetOrders method to get the list of orders with the following code.

    public OrderReturnValue GetOrders(OrderParameterValue orderParameter)
    {
        // Create an object of Return Value class
        OrderReturnValue returnValue = new OrderReturnValue();
    
        // Create an object of common DAO and assign SQL file
        CmnDao dao = new CmnDao(this.Dam);
        dao.SQLFileName = "SelectOrders.sql";
    
        // Create an object of DataTable
        System.Data.DataTable table = 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;
    }
  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 OrderReturnValue GetOrderById(OrderParameterValue orderParameter)
    {
        // Create an object of Return Value class
        OrderReturnValue returnValue = new OrderReturnValue();
    
        // Create an object of auto generated DAO classes
        DaoOrders orderDao = new DaoOrders(this.Dam);
        DaoOrder_Details orderDetailsDao = new DaoOrder_Details(this.Dam);
    
        // Create objects of DataTable to store the details of specified order information
        System.Data.DataTable orderTable = new System.Data.DataTable();
        System.Data.DataTable orderDetailsTable = 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;
    }
  8. Create UpdateOrder method to update the details of specified order summary and order details information with the following code.

    public OrderReturnValue UpdateOrder(OrderParameterValue orderParameter)
    {
        // Create an object of Return Value class
        OrderReturnValue returnValue = new OrderReturnValue();
    
        // Create an object of auto generated DAO classes
        DaoOrders orderDao = new DaoOrders(this.Dam);
        DaoOrder_Details orderDetailsDao = new DaoOrder_Details(this.Dam);
    
        // Create an object of DataTable to store order information and order details information
        System.Data.DataTable orderTable = orderParameter.Orders;
        System.Data.DataTable orderDetailsTable = orderParameter.OrderDetails;
    
        // Judge the state of DataRow, and update database if DataRow is modified
        if (orderTable.Rows[0].RowState == System.Data.DataRowState.Modified)
        {
            // Set the parameters of the order information
            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();
        }
    
        foreach (System.Data.DataRow row in orderDetailsTable.Rows)
        {
            // Judge the state of DataRow, and update database if DataRow is modified
            if (row.RowState == System.Data.DataRowState.Modified)
            {
                // 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();
            }
        }
    
        // Return result value
        return returnValue;
    }

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.cs.

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

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

    public class OrdersLogic : MyFcBaseLogic
  5. Create UOC_GetOrders method to get the list of orders with the following code.

    private void UOC_GetOrders(OrderParameterValue orderParameter)
    {
        // Create an object DAO Summary class
        ConsolidatedLayerD facade = new ConsolidatedLayerD(this.GetDam());
    
        // Get the list of orders information
        OrderReturnValue returnValue = facade.GetOrders(orderParameter);
    
        // Return the object of Return Value class
        this.ReturnValue = returnValue;
    }

    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 void UOC_GetOrderById(OrderParameterValue orderParameter)
    {
        // Create an object DAO Summary class
        ConsolidatedLayerD facade = new ConsolidatedLayerD(this.GetDam());
    
        // Get the details of specific order information and order details information based on Order ID
        OrderReturnValue returnValue = facade.GetOrderById(orderParameter);
    
        // Return the object of Return Value class
        this.ReturnValue = returnValue;
    }
  7. Create UOC_UpdateOrder method to update the details of specified order summary and order details information with the following code.

    private void UOC_UpdateOrder(OrderParameterValue orderParameter)
    {
        // Create an object DAO Summary class
        ConsolidatedLayerD facade = new ConsolidatedLayerD(this.GetDam());
    
        // Update the specified order information and order details information
        OrderReturnValue returnValue = facade.UpdateOrder(orderParameter);
    
        // Return the object of Return Value class
        this.ReturnValue = returnValue;
    }

4.7 Implement code behind

4.7.1 Implement code behind of master page

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

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

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

    public partial class TouryoMaster : 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.cs.

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

    protected string UOC_lbnGetOrdersList_Click(FxEventArgs eventArgs)
    {
        // Transfer screen according to the value defined in SCDefinitions.xml
        return "List";
    }
    
    protected string UOC_lbnShowDialog_Click(FxEventArgs eventArgs)
    {
        // Show modal dialog
        this.ShowNormalScreen("/WebForms_Sample/Aspx/sample/test.pdf");
    
        // Return empty string
        return string.Empty;
    }

    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.cs.

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

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

    public partial class OrdersList : 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 override void UOC_FormInit()
    {
        // Create parameter class
        // (Send "GetOrders" as parameter to call UOC_GetOrders in business logic class)
        OrderParameterValue param = new OrderParameterValue(this.ContentPageFileNoEx, "", "GetOrders", "SQL", this.UserInfo);
    
        // Create return value class
        OrderReturnValue returnValue;
    
        // Call business logic class
        OrdersLogic logic = new OrdersLogic();
        returnValue = (OrderReturnValue)logic.DoBusinessLogic(param);
    
        // Display the result in gridview.
        this.gvwOrdersList.DataSource = returnValue.Orders;
        this.gvwOrdersList.DataBind();
    }
    
    protected override void UOC_FormInit_PostBack()
    {
    }
  7. Add a method to OrdersList.aspx.cs for transitioning to order details form when clicking the button in each rows of gridview.

    protected string UOC_gvwOrdersList_RowCommand(FxEventArgs eventArgs)
    {
        // Get index of selected row
        int RowIndex = int.Parse(eventArgs.PostBackValue);
    
        // Get Order Id of selected row
        string OrderId = this.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";
    }

4.7.4 Implement code behind of order detail form

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

  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 override void UOC_FormInit()
    {
        // Get Order Id from session
        string OrderId = Session["OrderId"].ToString();
    
        // Create parameter class
        // (Send "GetOrderById" as parameter to call UOC_GetOrderById in business logic class)
        OrderParameterValue param = new OrderParameterValue(this.ContentPageFileNoEx, "", "GetOrderById", "SQL", this.UserInfo);
    
        // Send order id for search criteria
        param.OrderId = OrderId;
    
        // Create return value class
        OrderReturnValue returnValue;
    
        // Call business logic class
        OrdersLogic logic = new OrdersLogic();
        returnValue = (OrderReturnValue)logic.DoBusinessLogic((BaseParameterValue)param);
    
        // Store order information in session
        Session["Orders"] = returnValue.Orders;
        Session["OrderDetails"] = returnValue.OrderDetails;
    
        // Display result in gridview
        this.gvwOrderSummary.DataSource = returnValue.Orders;
        this.gvwOrderSummary.DataBind();
        this.gvwOrderDetails.DataSource = returnValue.OrderDetails;
        this.gvwOrderDetails.DataBind();
    }
    
    protected override void UOC_FormInit_PostBack()
    {
    }
  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.cs, implement as follows:

    protected void gvwOrderSummary_RowEditing(object sender, GridViewEditEventArgs e)
    {
        // Switch gvwOrderSummary to edit mode
        this.gvwOrderSummary.EditIndex = e.NewEditIndex;
        this.gvwOrderSummary.DataSource = (System.Data.DataTable)Session["Orders"];
        this.gvwOrderSummary.DataBind();
    
        // Set primary key and foreign key columns as read only
        ((TextBox)this.gvwOrderSummary.Rows[e.NewEditIndex].Cells[1].Controls[0]).Enabled = false;
        ((TextBox)this.gvwOrderSummary.Rows[e.NewEditIndex].Cells[2].Controls[0]).Enabled = false;
        ((TextBox)this.gvwOrderSummary.Rows[e.NewEditIndex].Cells[3].Controls[0]).Enabled = false;
    }
    
    protected void gvwOrderSummary_RowCancelingEdit(object sender,
    GridViewCancelEditEventArgs e)
    {
        // Switch gvwOrderSummary to display mode
        this.gvwOrderSummary.EditIndex = -1;
        this.gvwOrderSummary.DataSource = (System.Data.DataTable)Session["Orders"];
        this.gvwOrderSummary.DataBind();
    }

    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.cs for saving the changes of order information (summary).

    protected string UOC_gvwOrderSummary_RowUpdating(FxEventArgs eventArgs, GridViewUpdateEventArgs e)
    {
        // Save the changes of order information (summary)
        System.Data.DataTable Orders = (System.Data.DataTable)Session["Orders"];
        foreach (string key in e.NewValues.Keys)
        {
            Orders.Rows[0][key] = e.NewValues[key];
        }
    
        // Switch gvwOrderSummary to display mode
        this.gvwOrderSummary.EditIndex = -1;
        this.gvwOrderSummary.DataSource = (System.Data.DataTable)Session["Orders"];
        this.gvwOrderSummary.DataBind();
    
        // Return empty string (Don't need screen transition)
        return string.Empty;
    }
  10. In the same way, add RowEditing event handler, RowCancelingEdit event handler, UOC_gvwOrderDetails_RowUpdating methods to gvwOrderDetails control. Implement as follows:

    protected void gvwOrderDetails_RowEditing(object sender, GridViewEditEventArgs e)
    {
        // Switch order information (Details) to edit mode
        this.gvwOrderDetails.EditIndex = e.NewEditIndex;
        this.gvwOrderDetails.DataSource = (System.Data.DataTable)Session["OrderDetails"];
        this.gvwOrderDetails.DataBind();
    
        // Set primary key and foreign key read only
        ((TextBox)this.gvwOrderDetails.Rows[e.NewEditIndex].Cells[1].Controls[0]).Enabled = false;
        ((TextBox)this.gvwOrderDetails.Rows[e.NewEditIndex].Cells[2].Controls[0]).Enabled = false;
    }
    
    protected void gvwOrderDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        // Switch order information (details) to display mode
        this.gvwOrderDetails.EditIndex = -1;
        this.gvwOrderDetails.DataSource = (System.Data.DataTable)Session["OrderDetails"];
        this.gvwOrderDetails.DataBind();
    }
    
    protected string UOC_gvwOrderDetails_RowUpdating(FxEventArgs eventArgs, GridViewUpdateEventArgs e)
    {
        // Save the changes of order information (details)
        System.Data.DataTable OrderDetails = (System.Data.DataTable)Session["OrderDetails"];
        foreach (string key in e.NewValues.Keys)
        {
            OrderDetails.Rows[e.RowIndex][key] = e.NewValues[key];
        }
    
        // Switch order infroamtion (details) to display mode
        this.gvwOrderDetails.EditIndex = -1;
        this.gvwOrderDetails.DataSource = (System.Data.DataTable)Session["OrderDetails"];
        this.gvwOrderDetails.DataBind();
    
        // Return empty string (Don't need screen transition)
        return string.Empty;
    }
  11. Add a method for reflecting the changes on database.

    protected string UOC_btnUpdateOrder_Click(FxEventArgs eventArgs)
    {
        // Get the value of gridview from session
        System.Data.DataTable orderTable = (System.Data.DataTable)Session["Orders"];
        System.Data.DataTable orderDetailTable = (System.Data.DataTable)Session["OrderDetails"];
    
        // Create parameter value class
        OrderParameterValue param = new OrderParameterValue(this.Title, "", "UpdateOrder", "SQL", this.UserInfo);
    
        // Send the value of gridview to business logic class
        param.Orders = orderTable;
        param.OrderDetails = orderDetailTable;
    
        // Create return value class
        OrderReturnValue returnValue;
    
        // Call business logic class
        OrdersLogic logic = new OrdersLogic();
        returnValue = (OrderReturnValue)logic.DoBusinessLogic(param);
    
        // Return empty string (Don't need screen transition)
        return string.Empty;
    }

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/WebForms_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