Repository navigation
UserGuide_Developers
This is a English page.
Click here for Japanese version of this file.
Updated in July 2026
- SEs and developers who develop applications with Open Touryo
This document summarizes the points that developers should know. A developer is a person who takes the task of implementing each piece of business processing (in subclasses, etc.).
Company names and product names in this document are trademarks or registered trademarks of their respective companies.
Legend in the figures:
- Red frame: code blocks that must be implemented
- Red frame (dashed): code blocks that require attention when implementing
- Blue text: code blocks that can be implemented freely
※ The content of each figure is also given as code below the figure (you can refer to the code even if the figure is not displayed).
1. Preparing the "parameter class" and "return value class"
2. How to use the B layer framework
3. How to use the D layer framework
- 3.1 Creating the "data access class"
- 3.2 Implementing methods in the "data access class"
- 3.3 Creating SQL
4. How to use the P layer framework
- 4.1 Creating the "content page (screen code class)"
- 4.2 Calling methods of the "business code class"
Before implementing the D and B layers, create the "parameter class" and "return value class" needed for the implementation.
- Create the "parameter class" and "return value class" as necessary.
- The class names can be changed to any name.
Implementation templates are shown below. You can refer to the implementation of the "TestParameterValue" and "TestReturnValue" classes attached to the sample programs.
using ProjectName.Infrastructure.Business.Common;
public class TestParameterValue : MyParameterValue // Inherits the "parameter parent class 2"
{
// Define additional elements required for the "parameter class"
public int ShipperID;
public string CompanyName;
public string Phone;
#region Constructor
public TestParameterValue(string screenId, string controlId, string methodName, string actionType)
: base(screenId, controlId, methodName, actionType)
{
// Required to pass the arguments to the constructor of the base.
}
#endregion
}Figure 1-1 Implementation template of the "parameter class"
using ProjectName.Infrastructure.Business.Common;
public class TestReturnValue : MyReturnValue // Inherits the "return value parent class 2"
{
// Define additional elements required for the "return value class"
public object Obj;
public int ShipperID;
public string CompanyName;
public string Phone;
}Figure 1-2 Implementation template of the "return value class"
Business processing is implemented in the "business code class".
- Create the "business code class" as necessary.
- Inherit the "MyFcBaseLogic" class.
- The class name can be changed to any name.
The implementation template is shown below (you can refer to the sample "LayerB" class).
#region using
// System~
using System;
~
using ProjectName.Infrastructure.Business.Business;
#endregion
/// <summary>
/// Overview of LayerB
/// </summary>
public class LayerB : MyFcBaseLogic // Inherits the "business code parent class 2"
{
}Figure 2.1 Implementation template of the "business code class"
When implementing "business processing" in the "business code class", the "UOC_DoAction" method of the "business code parent class 2" implements the "automatic dispatching of business processing methods". Following this dispatching, add a UOC method to the "business code class" to implement the "business processing".
The dispatching generates a method name using the "methodName" property in the parameter of the "parameter parent class 1" and dispatches the processing by late binding. The "dispatching logic" can be customized freely, but by default the method "UOC_(string specified in methodName)" is called by late binding.
/// <summary>Implements the business processing corresponding to btnButton1</summary>
/// <param name="parameterValue">Parameter class</param>
private void UOC_(method name)(XParameterValue xParameter)
{
// Create the return value class
XReturnValue xReturn = new XReturnValue();
// Set the return value
this.ReturnValue = xReturn;
// ↓Business processing-----------------------------------------------------
// Create the data access class
LayerD myDao = new LayerD(this.GetDam());
myDao.xxxx(xParameter, xReturn);
// ↑Business processing-----------------------------------------------------
}Figure 2.2 Implementation example of a "business processing method" of the "business code class"
- The parameter class can be defined per business as the type of the method argument (it does not need to be defined with the type of the base class), so no cast is needed.
- A "data access class" is created for data access (see the next chapter for how to create it).
- To return the return value of "business processing", you must use the
this.ReturnValuemember variable (this makes the return value returned even when an exception occurs). It is a good idea to set the reference of the local variable to the member variable at the beginning of the method. - To roll back the transaction, throw a "business exception" inside the "business processing". The transaction is also rolled back when a "system exception" is thrown or "other general exceptions" occur. In all other cases (when the B layer ends normally), the transaction is committed entirely.
Data access processing of the business is implemented in the "data access class".
- Create the "data access class" as necessary.
- The class name can be changed to any name.
The implementation template is shown below (you can refer to the sample "LayerD" class).
#region using
// Import the necessary namespaces.
// System~
using System;
~
using ProjectName.Infrastructure.Public.Util;
#endregion
/// <summary>
/// Overview of LayerD
/// </summary>
public class LayerD : MyBaseDao // Inherits the "data access parent class 2"
{
/// <summary>Constructor</summary>
public LayerD(BaseDam dam) : base(dam)
{
// Basically nothing is implemented
}
}Figure 3.1 Implementation template of the "data access class"
When creating the D layer in the B layer, set the "data access control class" in the constructor. The D layer holds this "data access control class" and uses it for data access.
To implement "data access processing" in the "data access class", implement methods using the following template (the method signature does not have to follow the definition of the template below).
#region Template
public void Template(TestParameterValue testParameter, TestReturnValue testReturn)
{
// ↓DB access-----------------------------------------------------
// ● Set the SQL by one of the following methods.
// -- When reading from a file.
this.SetSqlByFile2("file name");
// -- When specifying directly.
this.SetSqlByCommand("SQL statement");
// ● Set parameters for the SQL by the following methods.
// Dynamically set values for the parameters of the parameterized query.
this.SetParameter("P1", testParameter.ShipperID);
// Replace the user-defined parameters (do not specify %%).
this.SetUserParameter("SEQUENCE", "DESC");
// ● Execute the SQL by one of the following methods.
object obj;
// -- For insert, update and delete (the number of rows can be checked)
obj = this.ExecInsUpDel_NonQuery();
// -- When executing a SELECT query that returns the first cell of information
obj = this.ExecSelectScalar();
// -- When executing a SELECT query that returns table (or record) information (argument = DataTable)
obj = new DataTable();
this.ExecSelectFill_DT((DataTable)obj);
// -- When executing a SELECT query that returns table (or record) information (argument = DataSet)
obj = new DataSet();
this.ExecSelectFill_DS((DataSet)obj);
// -- Returns a data reader
IDataReader idr = (IDataReader)this.ExecSelect_DR();
// ↑DB access-----------------------------------------------------
// Set the return value
testReturn.Obj = obj;
}
#endregionFigure 3.2 Implementation example of "data access processing" in the "data access class"
In this framework, you can choose between the following two ways to specify SQL statements.
- Reading from a file
- Specifying directly using a literal (string constant) in the program
Use the API according to how the SQL is specified.
-
When reading from a file: Get the SQL file storage folder with the
GetConfigParameter.GetConfigValuemethod, concatenate the SQL file name withPath.Combine, and pass it as the path argument of theSetSqlByFilemethod. In the latest version, theSetSqlByFile2method is recommended (internally it supports concatenation with the sqlTextFilePath parameter and reading from embedded resources).
// -- When reading from a file.
this.SetSqlByFile(
Path.Combine(GetConfigParameter.GetConfigValue("sqlTextFilePath"), "file name"));// -- When reading from a file or an embedded resource.
// To read from an embedded resource, the following setting is required.
// MyBaseDao.UseEmbeddedResource = true;
this.SetSqlByFile2("file name");Figure 3.3.1-1 When reading SQL from a file
-
When specifying directly: Specify the string literal of the SQL statement in the SQL argument of the
SetSqlByCommandmethod.
// -- When specifying directly.
this.SetSqlByCommand("SQL statement");Figure 3.3.1-2 When specifying SQL directly
User-defined parameters can be defined in SQL and replaced from the program using the API. An example of dynamically generating SQL is shown below.
- Define user-defined parameters in the SQL (user-defined parameters are enclosed in
%).
SELECT c1, c2, c3 FROM t1 %Where% ORDER BY %COLUMN% %SEQUENCE%Figure 3.3.2-1 When user-defined parameters are defined in SQL
- Specify the SQL using the
SetSqlByCommandmethod or theSetSqlByFile(SetSqlByFile2)method. - Replace the user-defined parameters using the
SetUserParametermethod.
- %Where% →(replaced)→ WHERE c4 = @p_c4, c5 = @p_c5
- %COLUMN% →(replaced)→ c2
- %SEQUENCE% →(replaced)→ DESC
// Replace the user-defined parameters (do not specify %%).
this.SetUserParameter("SEQUENCE", "DESC");Figure 3.3.2-2 When replacing user-defined parameters
- The completed SQL (parameterized query).
SELECT c1, c2, c3 FROM t1 WHERE c4 = @p_c4, c5 = @p_c5 ORDER BY c2 DESCFigure 3.3.2-3 The completed SQL (parameterized query)
- Set the parameters of this parameterized query and execute the SQL (explained in the next section).
※ User-defined parameters have no SQL injection protection, so either check the replacement string variables in the program, or do not specify user input directly as a replacement string variable. Basically, specify user input as a parameter of the parameterized query.
It is the de facto standard to use parameterized queries for SQL, from the viewpoints of SQL injection protection and reuse of query plans in dynamic SQL such as conditional searches. Note that how to define parameterized queries differs by DBMS.
- In SQL Server, parameters are defined as "@ + parameter name".
- In Oracle, parameters are defined as ": + parameter name".
Table 3.3.3 Examples of parameterized queries in SQL Server and Oracle
| No. | Category | SQL Server example | Oracle example |
|---|---|---|---|
| 1 | INSERT | INSERT INTO Shippers (CompanyName, Phone) VALUES (@P2, @P3) |
INSERT INTO Shippers (CompanyName, Phone) VALUES (:P2, :P3) |
| 2 | UPDATE | UPDATE Shippers SET CompanyName = @P2, Phone = @P3 WHERE ShipperID = @P1 |
UPDATE Shippers SET CompanyName = :P2, Phone = :P3 WHERE ShipperID = :P1 |
| 3 | DELETE | DELETE Shippers WHERE ShipperID = @P1 |
DELETE Shippers WHERE ShipperID = :P1 |
| 4 | SELECT | SELECT ShipperID, CompanyName, Phone FROM Shippers WHERE ShipperID = @P1 |
SELECT ShipperID, CompanyName, Phone FROM Shippers WHERE ShipperID = :P1 |
To set values for the parameters of a parameterized query, use the SetParameter method. The overloaded methods also allow specifying the data types of each data provider, etc.
// Dynamically set values for the parameters of the parameterized query.
this.SetParameter("P1", testParameter.ShipperID);Figure 3.3.4 Method to specify parameters of a parameterized query
The following five methods can be used to execute SQL.
// -- For insert, update and delete (the number of rows can be checked)
obj = this.ExecInsUpDel_NonQuery();
// -- When executing a SELECT query that returns one cell of information
obj = this.ExecSelectScalar();
// -- SELECT query that returns table (or record) information (argument = DataTable)
obj = new DataTable();
this.ExecSelectFill_DT((DataTable)obj);
// -- SELECT query that returns table (or record) information (argument = DataSet)
obj = new DataSet();
this.ExecSelectFill_DS((DataSet)obj);
// -- Returns a data reader
IDataReader idr = (IDataReader)this.ExecSelect_DR();Figure 3.3.5 The five methods used to execute SQL
Table 3.3.5 Relationship between each method and the SQL to execute / return value
| No. | Category | Available methods | Return value |
|---|---|---|---|
| 1 | INSERT | ExecInsUpDel_NonQuery() | Returns the number of affected (inserted) rows. |
| 2 | UPDATE | ExecInsUpDel_NonQuery() | Returns the number of affected (updated) rows. |
| 3 | DELETE | ExecInsUpDel_NonQuery() | Returns the number of affected (deleted) rows. |
| 4 | SELECT | ExecSelectScalar() | Returns the first cell of information of the result set. |
| 4 | SELECT | ExecSelectFill_DT() | Returns the result set (DataTable type). ※ Pass a DataTable argument. |
| 4 | SELECT | ExecSelectFill_DS() | Returns the result set (DataTable type). ※ Pass a DataSet argument. |
| 4 | SELECT | ExecSelect_DR() | Returns a data reader. |
P layer event processing is implemented in the "content page (screen code class)".
- Create the "content page (screen code class)" as necessary.
- The class name can be changed to any name.
Right-click anywhere in Solution Explorer and select [Add New Item] to display the [Add New Item] dialog. Select "Web Form" from the templates, turn on the [Select master page] check box, and create the content page.
Figure 4.1.1-1 [Add New Item] dialog
The [Select a Master Page] dialog is then displayed, so select the "master page" to be used in the "content page (screen code class)".
Figure 4.1.1-2 [Select a Master Page] dialog
The above operations create a content page like the following.
<%@ Page Language="C#" MasterPageFile="~/Aspx/Common/TestScreen.master" AutoEventWireup="true"
CodeFile="testScreen.aspx.cs" Inherits="Aspx_testFxLayerP_testScreen" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>Figure 4.1.1-3 The created content page
※ ContentPlaceHolders are automatically generated on the content page to match the structure of the selected master page. The implementation inside a ContentPlaceHolder can be changed freely by the user.
After creating and designing the "content page", implement the processing in the "screen code class", which is the code-behind. The implementation template is shown below.
// Import the necessary namespaces.
// System~
using System;
~
using ProjectName.Infrastructure.Business.Util;
public partial class Aspx_testFxLayerP_testScreen : MyBaseController // Inherits the "screen code parent class 2"
{
}Figure 4.1.1-4 Implementation template of the "screen code class"
"Page load processing" must be implemented. Override the "UOC_FormInit" and "UOC_FormInit_PostBack" methods in the "screen code class" to implement the first load and postbacks separately.
#region UOC methods for page load
/// <summary>UOC method for page load (individual: first load)</summary>
/// <remarks>Must be implemented</remarks>
protected override void UOC_FormInit()
{
// Implement the processing to run at form initialization (first load)
// TODO:
}
/// <summary>UOC method for page load (individual: postback)</summary>
/// <remarks>Must be implemented</remarks>
protected override void UOC_FormInit_PostBack()
{
// Implement the processing to run at form initialization (postback)
// TODO:
}
#endregionFigure 4.1.2 Implementation example of "page load processing"
Follow these steps.
- Place a control ([prefix] + any string) on the "master page".
- Implement the UOC method
UOC_(master page file name)_[prefix]anyString_Clickin the "screen code class".
- On the "master page" (example when the custom button control is selected)
<cc1:WebCustomButton ID="btnMasterIdvdl" runat="server" Text="(button display name)" Width="220px" /><br />Figure 4.1.3-1 Implementation example of the "master page"
-
In the "screen code class": The signature of the event handler is
protected string eventHandlerName(FxEventArgs fxEventArgs)(for GridView RowUpdating / RowDeleting / PageIndexChanging / Sorting, it is(FxEventArgs fxEventArgs, EventArgs e)). When the master page file name is "TestScreen.master":
protected string UOC_TestScreen_btnMasterIdvdl_Click(FxEventArgs fxEventArgs)
{
// TODO:
// For a postback without screen transition, set the url to an empty string
return "";
}Figure 4.1.3-2 Implementation example of the "screen code class"
UOC methods that implement event processing are called by late binding from the common event handler, so they must be defined as "public" or "protected" ("private" in aspx.cs(vb) is special and cannot be late-bound). Returning a URL causes a screen transition, and returning an empty string causes a postback without screen transition.
Follow these steps.
- Place a control ([prefix] + any string) on the content page.
- Implement the UOC method
UOC_[prefix]anyString_Clickin the "screen code class".
- Implementation example on the content page (example when the custom button control is selected)
<cc1:WebCustomButton ID="btnCntnt" runat="server" Text="(button display name)" Width="220px" /><br />Figure 4.1.4-1 Implementation example on the content page
- Implementation example in the "screen code class":
protected string UOC_btnCntnt_Click(FxEventArgs fxEventArgs)
{
// TODO:
// For a postback without screen transition, set the url to an empty string
return "";
}Figure 4.1.4-2 Implementation example in the "screen code class"
UOC methods that implement event processing are called by late binding from the common event handler, so they must be defined as "public" or "protected" ("private" in aspx.cs(vb) is special and cannot be late-bound). Returning a URL causes a screen transition, and returning an empty string causes a postback without screen transition.
The processing that calls methods of the "business code class" is mainly implemented in the "event processing of controls". A sample of the call processing is shown below (you can refer to the "screen code class" of the samples).
/// <summary>Event handler</summary>
/// <param name="fxEventArgs">Common argument of the event handler</param>
/// <returns>URL</returns>
protected string UOC_(any event handler name)(FxEventArgs fxEventArgs)
{
// Create the parameter class (set the parameter values)
TestParameterValue testParameterValue
= new TestParameterValue(
this.ContentPageFileNoEx, // String representing the screen
fxEventArgs.ButtonID, // Control ID of the event source
"(any methodName value)", // Name of the B layer method to call
"(any actionType value)", // Parameter used for conditional branching, etc.
this.UserInfo); // User information (added in base 2)
// Set the isolation level
DbEnum.IsolationLevelEnum iso = this.SelectIsolationLevel();
// Create the B layer
LayerB myBusiness = new LayerB();
// Execute the business processing
TestReturnValue testReturnValue =
(TestReturnValue)myBusiness.DoBusinessLogic(
(BaseParameterValue)testParameterValue, iso);
// Message area to display the result
Label label = (Label)this.GetMasterWebControl("Label1");
label.Text = "";
if (testReturnValue.ErrorFlag == true)
{
// Result (business-continuable error)
label.Text = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\n";
label.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\n";
label.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\n";
}
else
{
// Result (normal case)
label.Text = testReturnValue.Obj.ToString();
}
// For a postback without screen transition, set the url to an empty string
return "";
}Figure 4.2 Method call processing of the "business code class"
-End-
Copyright © 2007,2017, Hitachi Solutions, Ltd.