The Dynacom Framework provides an object model based on ActiveX Data Objects to access data. At the core of this object model is a concept known as Data Object. A data object consists of a collection of tables and includes business rules to validate and manage data. Dynacom Accounting has many built-in data objects, like customers or invoices. Using each specific data object to manipulate data instead of accessing the database directly ensures complete data integrity and even provides many useful features.
Starting from the sample from my last post, it is easy to add some code and list all customers from the selected database in a ListView control.
To instantiate a data object, you first need to identify it. These values are provided in a library not yet referenced by our project: Dynacom.Accounting.Foundation.dll. This library contains the entry point to everything that is accounting-related.
Next, add a form to the project and then a ListView onto the form. Create a function to fill the ListView. A data object variable can be declared as follows:
DynaFoundation.CDataObject customers;
Instantiating a data object requires a more intricate knowledge of the framework:
customers = Dynacom.Foundation.Application.BusinessObjectsUtils.GetDataObject(Dynacom.Accounting.Foundation.Application.AppObject.Declares.DATA_CUST);
The GetDataObject method loads the data object definition file identified by the GUID passed as the single parameter which, in this case, corresponds to the Customers data object. Many other data objects are available with Dynacom Accounting.
A data object always contains one and only one header table which can be related or not to one or many detail tables. The Dynacom Framework uses the term Section to refer to a table.
There are two very important interfaces to know about to properly use a data object: ISection and IDataSet, defined in the DynaILib namespace. A table, or section, always implements both interfaces. The first is used to identify and define the section while the other serves to navigate the data source.
You can define two variables, one of each type, to improve performance and code readability:
DynaILib.ISection header;
DynaILib.IDataSet dataSet;
<...>
header = customers.Sections.Header;
dataSet = header.DataSet;
Retrieving data is as simple as calling the OpenObject method on the IDataSet interface. There is no need to provide a SQL query since the data object itself knows what data it should retrieve. However, the method provides many parameters to filter data and control performance. Most of these parameters are optional
(the method is defined in a Visual Basic 6 interface), but since optional parameters are not part of the C# language definition, you must provide a value for each of them. To simply retrieve read-only data, the following values can be specified:
dataSet.OpenObject((DynaILib.OpenModeEnum)((int)DynaILib.OpenModeEnum.omReadOnly + (int)DynaILib.OpenModeEnum.omForwardOnly), "", 0, "", DynaILib.OpenOptionsEnum.ooDefault, null, true)
Once the data set is open, you can access the data by using the ISection interfaces and its Members property. Members refer to columns in the table, or section. You can easily retrieve the value of a specific member with the following line of code:
(string)header.Members.get_Item("name").Value.CurrentValue
The attached sample shows how to fill a ListView control with the names of all customers in the database.
In my next post, I will introduce a few special features which simplify data access.