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

Open Touryo Tutorial (Two-tier client server application (VB) edition)

November 27th, 2014

Introduction

Objective of this document

The objective is to learn the development of two-tier client server 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 two-tier client server application with an example.

Scope of this document

Scope of this tutorial is learning how to use Open Touryo framework in two-tier client server application.

Overview of this document

This tutorial describes the development flow for two-tier client server 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
    • DB
      • SQL Server Express 2008 R2
  • Others
    • OS
      • Windows 7
    • Programming language
      • Visual Basic

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\VB\Samples\2CS_sample\2CSClientWin_sample\2CSClientWin_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 orders list form

  1. In Visual Studio, click Project -> Add Windows Forms in toolbar.

  2. Add new windows form named OrdersForm.vb.

  3. Add Button control and DataGridView control to OrdersForm.vb as following image.

    Set the properties respectively as follows:

    • Button
      • Name: btnShowOrderDetail
      • Text: Display order details
    • DataGridView
      • AllowUserToAddRows: false
      • AllowUserToDeleteRows: false

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

4.2.2 Create order details form

  1. In the same way to section 4.2.1, create a form that displays the order details. Here, name the form OrderDetailsForm.vb.

  2. Add two Label controls, two DataGridView controls and Button control to OrderDetailsForm as following image.

    Set it as below respectively.

    • Label (Upper part)
      • Text: Order information (Summary)
    • Label (Lower part)
      • Text: Order information (Details)
    • Button
      • Name: btnUpdateOrder
      • Text: Update order Information
    • DataGridView (Both)
      • AllowUserToAddRows: false
      • AllowUserToDeleteRows: false

4.3 Create Parmeter and Return value class

4.3.1 Create Parameter Value class

  1. Select Common folder in the Solution Explorer. And 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.

    Import Touryo.Infrastructure.Business.Util
    Import 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>
    Public Orders As System.Data.DataTable
    
    ''' <summary>Order details information</summary>
    Public OrderDetails As System.Data.DataTable

4.3.2 Create Return Value class

  1. In the same way to section 4.3.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>
    Public Orders As System.Data.DataTable
    
    ''' <summary>Order details information</summary>
    Public OrderDetails As System.Data.DataTable

4.4 Implement common exception handler

  1. In the Solution Explorer, open Program.vb.

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

    Imports Touryo.Infrastructure.Framework.RichClient.Business
  3. In the sample program, Application_ThreadException method is prepared as a common exception handler. Here, implement the process that rolls back the database transaction.

    Public Shared Sub Application_ThreadException(sender As Object, e As ThreadExceptionEventArgs)
      ' Rollback the database transaction (Nothing is done when not connecting to database)
      BaseLogic2CS.RollbackAndClose()
    
      ShowErrorMessage(e.Exception, "Application_ThreadExceptionによる例外通知です。")
    End Sub

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

    '  Open Touryo
    Imports Touryo.Infrastructure.Business.Dao
    Imports Touryo.Infrastructure.Public.Db
    
    ' Parameter and return value class
    Imports _2CSClientWin_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
        ' 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()
      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 the object of Return Value Class to business logic class
      Return returnValue
    End Function

4.6 Create business logic class

  1. Select Business folder in the Solution Explorer. And 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
    Imports Touryo.Infrastructure.Business.RichClient.Asynchronous
    Imports Touryo.Infrastructure.Business.RichClient.Business
    Imports Touryo.Infrastructure.Business.RichClient.Presentation
    
    ' 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
    Imports Touryo.Infrastructure.Framework.RichClient.Presentation
    
    ' 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 _2CSClientWin_sample.Common
    
    ' Data access class
    Imports _2CSClientWin_sample.Dao
  4. Inherit Business Parent Class of Open Touryo framework to OrdersLogic class as shown below.

    Public Class OrdersLogic
      Inherits MyFcBaseLogic2CS
  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 forms is required to be created as UOC_xx (xx is arbitrary string). When the forms send 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 order list form

  1. In the Solution Explorer, right-click OrdersForm.vb and select View Code option.

  2. Add the following namespaces to OrdersForm.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
    Imports Touryo.Infrastructure.Business.RichClient.Asynchronous
    Imports Touryo.Infrastructure.Business.RichClient.Presentation
    
    ' 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
    Imports Touryo.Infrastructure.Framework.RichClient.Business
    Imports Touryo.Infrastructure.Framework.RichClient.Presentation
    
    ' 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 _2CSClientWin_sample.Common
    
    ' Business logic class
    Imports _2CSClientWin_sample.Business
  3. Inherit Screen Parent Class of Open Touryo to OrdersForm class as shown below.

    Public Class OrdersForm
      Inherits MyBaseControllerWin
  4. Override UOC_FormInit method to display the order information list during the form startup with the following code.

    Protected Overrides Sub UOC_FormInit()
      ' Create an object of Parameter value class
      Dim param As New OrderParameterValue(Me.Name, "", "GetOrders", "SQL", MyBaseControllerWin.UserInfo)
    
      ' Define the variable of Return value class
      Dim returnValue As OrderReturnValue
    
      ' Call the method of business logic class
      Dim logic As New OrdersLogic()
      returnValue = DirectCast(logic.DoBusinessLogic(param), OrderReturnValue)
    
      ' Initialize DataGridView.DataSource property
      Me.dataGridView1.DataSource = Nothing
    
      If returnValue.ErrorFlag = True Then
        ' Show error message
        MessageBox.Show("ErrorMessageID:" & returnValue.ErrorMessageID & vbCrLf _
          & "ErrorMessage:" & returnValue.ErrorMessage & vbCrLf _
          & "ErrorInfo:" & returnValue.ErrorInfo & vbCrLf)
      Else
        ' Display order information in DataGridView control
        Me.dataGridView1.DataSource = returnValue.Orders
    
        ' Make DataGridView control uneditable
        Me.dataGridView1.ReadOnly = True
      End If
    
      ' Commit transaction and close connection
      BaseLogic2CS.CommitAndClose()
    End Sub
  5. Add the click handler for the btnShowOrderDetail to display order details form.

    Protected Sub UOC_btnShowOrderDetail_Click(eventArgs As RcFxEventArgs)
      If Me.dataGridView1.SelectedRows.Count = 0 Then
        ' Show error message when the record in DataGridView is not selected
        MessageBox.Show("Record is not selected.")
        Return
      End If
    
      ' Create an object of OrderDetailsForm
      Dim orderDetailsForm As New OrderDetailsForm()
    
      ' Set OrderDetailsForm.Owner property to the object of OrderForm
      orderDetailsForm.Owner = Me
    
      ' Display OrderDetailsForm
      orderDetailsForm.Show()
    End Sub
  6. Create a property to get the OrderId of selected row in order information list.

    Public ReadOnly Property SelectedOrderId() As String
      Get
        If Me.dataGridView1.SelectedRows.Count = 0 Then
          ' Return nothing when the row in order information list is not selected
          Return Nothing
        Else
          ' Return OrderId of selected row
          Return Me.dataGridView1.SelectedRows(0).Cells(0).Value.ToString()
        End If
      End Get
    End Property

4.7.2 Implement code behind of order detail form

  1. In the same way to section 4.7.1, inherit Screen Parent Class of Open Touryo to OrderDetailsForm class.

  2. Override UOC_FormInit method to display the order details information during the form startup with the following code.

    Protected Overrides Sub UOC_FormInit()
      ' Create an object of Parameter value class
      Dim param As New OrderParameterValue(Me.Name, "", "GetOrderById", "SQL", MyBaseControllerWin.UserInfo)
      param.OrderId = DirectCast(Me.Owner, OrdersForm).SelectedOrderId
    
      ' Define the variable of Return value class
      Dim returnValue As OrderReturnValue
    
      ' Call the method of business logic class
      Dim logic As New OrdersLogic()
      returnValue = DirectCast(logic.DoBusinessLogic(param), OrderReturnValue)
    
      ' Initialize DataGridView.DataSource property
      Me.dataGridView1.DataSource = Nothing
      Me.dataGridView2.DataSource = Nothing
    
      If returnValue.ErrorFlag = True Then
        ' Show error message
        MessageBox.Show("ErrorMessageID:" & returnValue.ErrorMessageID & vbCrLf _
          & "ErrorMessage:" & returnValue.ErrorMessage & vbCrLf _
          & "ErrorInfo:" & returnValue.ErrorInfo & vbCrLf)
      Else
        ' Display order information in DataGridView control
        Me.dataGridView1.DataSource = returnValue.Orders
    
        ' Make specific columns of DataGridView control uneditable
        Me.dataGridView1.Columns("OrderId").ReadOnly = True
        Me.dataGridView1.Columns("CustomerId").ReadOnly = True
        Me.dataGridView1.Columns("EmployeeId").ReadOnly = True
    
        ' Display order details information in DataGridView control
        Me.dataGridView2.DataSource = returnValue.OrderDetails
    
        ' Make specific columns of DataGridView control uneditable
        Me.dataGridView2.Columns("OrderId").ReadOnly = True
        Me.dataGridView2.Columns("ProductId").ReadOnly = True
      End If
    
      ' Commit transaction and close connection
      BaseLogic2CS.CommitAndClose()
    End Sub
  3. Add the click handler for the btnUpdateOrder to update database.

    Protected Sub UOC_btnUpdateOrder_Click(eventArgs As RcFxEventArgs)
      ' Acquire DataGridView data
      Dim orderTable As DataTable = Me.dataGridView1.DataSource
      Dim orderDetailTable As DataTable = Me.dataGridView2.DataSource
    
      ' Create an object of Parameter value class
      Dim param As New OrderParameterValue(Me.Name, "", "UpdateOrder", "SQL", MyBaseControllerWin.UserInfo)
    
      ' Set the properties of Paramter value class to DataGridView data
      param.Orders = orderTable
      param.OrderDetails = orderDetailTable
    
      ' Define the variable of Return value class
      Dim returnValue  As OrderReturnValue
    
      ' Call the method of business logic class
      Dim logic As New OrdersLogic()
      returnValue = logic.DoBusinessLogic(param)
    
      If returnValue.ErrorFlag = true Then
        ' Rollback transaction and close connection
        BaseLogic2CS.RollbackAndClose()
    
        ' Show error message
        MessageBox.Show("ErrorMessageID:" & returnValue.ErrorMessageID & vbCrLf _
          & "ErrorMessage:" & returnValue.ErrorMessage & vbCrLf _
          & "ErrorInfo:" & returnValue.ErrorInfo & vbCrLf)
      Else
        ' Commit transaction and close connection
        BaseLogic2CS.CommitAndClose()
    
        ' Show message that database has been updated successfully
        MessageBox.Show("Updated database successfully")
      End If
    End Sub

4.8 Confirm the setting information

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

  1. In the Solution Explorer, open app.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 Change the startup form

Perform the following steps to display OrdersForm.vb when the sample application is executed.

  1. In the Solution Explorer, open Program.vb.

  2. Search for Application.Run in Program.vb, and revise as follows:

    ' Display Order information list
    Application.Run(New OrdersForm())

4.9.2 Debug the sample application

  1. Debug the sample application with Visual Studio.

  2. At the login form, enter the arbitrary alphanumeric characters. (By default, the password authentication is not executed.)

    Click ログイン (Login in Japanese).

  3. Confirm that the order information is displayed. Select any row and click Display order details.

  4. Confirm that order information and order details information are displayed. Edit order information and order details information. (OrderId, CustomerId, EmployeeId and ProductId cannot be edited) Click Update order information.

  5. Confirm that the message "Updated database successfully" is shown. Click OK.

  6. 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.]"

4.9.3 Confirm trace log

  1. Open log file - C:\root\programs\C#\Samples\2CS_sample\2CSClientWin_sample\bin\Debug\ACCESS_2CS.yyyy-mm-dd.log (where, yyyy-mm-dd is executed date) in Notepad.

  2. Confirm that the access to OrdersForm and OrderDetailsForm 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,pc01,----->>,OrdersForm,,GetOrders,
    [2017/04/06 11:25:03,008],[INFO ],[9],,user01,pc01,<<-----,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,pc01,----->>,OrderDetailsForm,,GetOrderById,
    [2017/04/06 11:28:49,486],[INFO ],[9],,user01,pc01,<<-----,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,pc01,----->>,OrderDetailsForm,,UpdateOrder,
    [2017/04/06 11:36:10,000],[INFO ],[9],,user01,pc01,<<-----,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\programs\C#\Samples\2CS_sample\2CSClientWin_sample\bin\Debug\SQLTRACE_2CS.yyyy-mm-dd.log (where, yyyy-mm-dd is executed date) in Notepad.

  4. Confirm the executed SQL text for Orders and Order Details 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