Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports C1.Data

' Remote service class: supports communication with the library
Public Class RemoteService
    Inherits C1.Data.RemoteDataService

    Public Function MyCustomFill(ByVal dataSetDefName As String, ByVal filterConditions As FilterConditions) As C1DataSet
        ' Business method: called from the client as c1DataSet1.RemoteDataService.CustomFill() both in 2-tier and 3-tier configurations.
        ' C1DataSet is serializable (has SerializableAttribute and implements ISerializable), so it can be passed
        ' to the server running on another machine.
        ' In this sample, the method just fills a data set and passes it back to the client.
        ' In real-life applications, you can add whatever logic you need in business methods, and add as many
        ' business methods as you need.
        Dim dataSet As C1DataSet = New C1DataSet()
        dataSet.DataLibrary = "DataLibrary"
        dataSet.SchemaClassName = "DataLibrary.DataClass"
        dataSet.DataSetDef = "DataSet"
        dataSet.Fill(filterConditions, False)
        Return dataSet
    End Function

    Public Function MyCustomUpdate(ByVal dataSet As C1DataSet) As C1DataSet
        ' Business method: called from the client as c1DataSet1.RemoteDataService.CustomFill() both in 2-tier and 3-tier configurations.
        ' C1DataSet is serializable (has SerializableAttribute and implements ISerializable), so it can be passed
        ' to the server running on another machine.
        ' In this sample, the method just calls Update.
        ' In real-life applications, you can add whatever logic you need in business methods, and add as many
        ' business methods as you need.
        dataSet.Update()
        Return dataSet
    End Function

    Public Overrides Sub Fill(ByVal dataSet As C1DataSet, ByVal filterConditions As FilterConditions, _
    ByVal diagEntityNames As String(), ByVal dynamicConnections As C1.Data.SchemaObjects.ConnectionCollection, ByVal beginTransaction As Boolean)
        ' You can call business methods to fill and update, as above, or you can rely on C1DataObjects doing fill/update automatically.
        ' If you rely on automatic Fill, this virtual method will be called each time you call C1DataSet.Fill
        ' (or at startup when the data set is filled due to FillOnRequest=True).
        ' You can override this virtual method to customize Fill behavior. For example,
        ' you can set beginTransaction = true, as below, to make C1DataObjects perform database fetch in
        ' a transaction (by default, transactions are not used in Fill, only in Update).
        ' Or you can set Connection.ConnectionString in the schema, or set Connection.DbConnection/DbTransaction
        ' directly to a pre-created connection/transaction object (see DataClass.cs, BeforeFetch event).
        ' You can also customize the Fill process in various other ways, including filling the dataSet manually
        ' instead of calling base.Fill().
        beginTransaction = True
        MyBase.Fill(dataSet, filterConditions, diagEntityNames, dynamicConnections, beginTransaction)
    End Sub

    Public Overrides Sub Update(ByVal dataSet As C1DataSet, ByVal dynamicConnections As C1.Data.SchemaObjects.ConnectionCollection, ByVal beginTransaction As Boolean)
        ' You can call business methods to fill and update, as above, or you can rely on C1DataObjects doing fill/update automatically.
        ' If you rely on automatic Update, this virtual method will be called each time you call C1DataSet.Update
        ' You can override this virtual method to customize Update behavior. For example,
        ' you can set beginTransaction = false, as below, to prevent C1DataObjects from using ADO.NET
        ' transactions in Update. By default, beginTransaction = true, which means C1DataObject uses
        ' ADO.NET transactions. This can be undesirable when you use COM+ automatic transactions
        ' (distributed transactions spanning multiple databases).
        beginTransaction = False
        ' To use distributed transactions, set beginTransaction = false here, and call a method in an object
        ' with appropriate TransactionAttribute, perform the Update in that method (for example, calling back to this
        ' object's base.Update() or calling a business method of this object).
        '
        ' Overriding this method, you can also change Connection.ConnectionString in the schema,
        ' or set Connection.DbConnection/DbTransaction directly to a pre-created connection/transaction object
        ' (see DataClass.cs, BeforeUpdate event).
        ' You can also customize the Update process in various other ways, including updating the database manually
        ' instead of calling base.Update().
        MyBase.Update(dataSet, dynamicConnections, beginTransaction)
    End Sub

End Class
