Table of Contents

Class DataModule

Namespace
Tripous.Data
Assembly
Tripous.Data.dll

Base class for all data modules.

A data module represents a table tree, such as SalesOrder along with a list SELECT table.

[TypeStore]
public class DataModule
Inheritance
DataModule
Derived
Inherited Members
Extension Methods

Constructors

DataModule()

Constructor

public DataModule()

Fields

ItemTables

The item tables only. tblList is not included."

public List<MemTable> ItemTables

Field Value

List<MemTable>

TableSet

Field

protected TableSet TableSet

Field Value

TableSet

fIsCommiting

Field

protected int fIsCommiting

Field Value

int

fIsDeleting

Field

protected int fIsDeleting

Field Value

int

fIsEditing

Field

protected int fIsEditing

Field Value

int

fIsInserting

Field

protected int fIsInserting

Field Value

int

fStocks

Field

protected List<MemTable> fStocks

Field Value

List<MemTable>

fVariables

Field

protected Dictionary<string, object> fVariables

Field Value

Dictionary<string, object>

Properties

CodeProviderDef

The code provider definition.

public CodeProviderDef CodeProviderDef { get; protected set; }

Property Value

CodeProviderDef

CurrentRow

Returns the first row of the tblItem.

WARNING: Valid only in insert and edit mode.

public virtual DataRow CurrentRow { get; }

Property Value

DataRow

DataSet

The DataSet of the module.

public DataSet DataSet { get; protected set; }

Property Value

DataSet

DetailsActive

When true then detail relationships are active.

public bool DetailsActive { get; set; }

Property Value

bool

Id

Returns the value of the Id field of the tblItem

public virtual object Id { get; }

Property Value

object

IsCommiting

True while commiting, that is while Commit() executes.

public bool IsCommiting { get; protected set; }

Property Value

bool

IsDeleting

True while deleting, that is while Delete() executes.

public bool IsDeleting { get; protected set; }

Property Value

bool

IsEditing

True while loading, that is while Edit() executes.

public bool IsEditing { get; protected set; }

Property Value

bool

IsInitialized

True if the module is initialized.

public bool IsInitialized { get; }

Property Value

bool

IsInserting

True while inserting, that is while Insert() executes.

public bool IsInserting { get; protected set; }

Property Value

bool

this[string]

An indexer with all tables

public MemTable this[string TableName] { get; }

Parameters

TableName string

Property Value

MemTable

LastCommitedId

Returns the Id of the last commit

public object LastCommitedId { get; protected set; }

Property Value

object

LastDeletedId

Returns the Id of the last delete

public object LastDeletedId { get; protected set; }

Property Value

object

LastEditedId

Returns the id of the item the last Edit() operation has loaded

public object LastEditedId { get; protected set; }

Property Value

object

ModuleDef

The module definition.

public ModuleDef ModuleDef { get; protected set; }

Property Value

ModuleDef

Name

The name of this module

public string Name { get; }

Property Value

string

RowProviderHost

The row provider host of this module. Typically the tblItem

public IRowProviderHost RowProviderHost { get; }

Property Value

IRowProviderHost

State

Returns the "data State" of the module. It could be Insert, Edit or None.

The State remains Insert or Edit after the Insert() or Edit() is called. A call to Commit() sets the State to Edit.

public DataMode State { get; protected set; }

Property Value

DataMode

Stocks

The stock tables.

public List<MemTable> Stocks { get; }

Property Value

List<MemTable>

Store

The SqlStore instance."/>

public SqlStore Store { get; protected set; }

Property Value

SqlStore

Tables

All tables, tblList included.

public IEnumerable<MemTable> Tables { get; }

Property Value

IEnumerable<MemTable>

Variables

Gets the variables of the module.

public Dictionary<string, object> Variables { get; protected set; }

Property Value

Dictionary<string, object>

tblItem

The top table of the table tree. Is always a single-row table.

public MemTable tblItem { get; protected set; }

Property Value

MemTable

tblList

The list table, the one that has the list SELECT data

public MemTable tblList { get; protected set; }

Property Value

MemTable

Methods

AssignCodeProviderDef()

Assigns the CodeProviderDef

protected virtual void AssignCodeProviderDef()

AssignCodeValue(DbTransaction)

Called from inside a commit transaction in order to assign the Code column

protected virtual void AssignCodeValue(DbTransaction Transaction)

Parameters

Transaction DbTransaction

BatchInsert(DataTable)

Inserts rows from a source table using batch commit.

public virtual void BatchInsert(DataTable tblSource)

Parameters

tblSource DataTable

BuildListSelectSql(string, JsonSelectFilters, out SelectDef)

Builds the SQL text for a list select operation.

protected virtual string BuildListSelectSql(string SelectName, JsonSelectFilters Filters, out SelectDef SelectDef)

Parameters

SelectName string
Filters JsonSelectFilters
SelectDef SelectDef

Returns

string

Cancel()

Rejects the changes after an insert or edit. Valid with master modules only.

public virtual void Cancel()

CheckCanCommit(bool)

Called by the Commit(bool) and throws an exception if, for some reason, commiting item is considered invalid.

public virtual void CheckCanCommit(bool Reselect)

Parameters

Reselect bool

CheckCanDelete(object)

Called by the Delete(object) and throws an exception if, for some reason, deleting the row in the database is considered invalid.

public virtual void CheckCanDelete(object RowId)

Parameters

RowId object

CheckCanEdit(object)

Called by the Edit(object) and throws an exception if, for some reason, starting an edit operation is considered invalid.

public virtual void CheckCanEdit(object RowId)

Parameters

RowId object

CheckCanInsert()

Called by the Insert() and throws an exception if, for some reason, starting an insert operation is considered invalid.

public virtual void CheckCanInsert()

ColumnChanged(MemTable, DataColumnChangeEventArgs)

Event handler

protected virtual void ColumnChanged(MemTable Table, DataColumnChangeEventArgs ea)

Parameters

Table MemTable
ea DataColumnChangeEventArgs

ColumnChanging(MemTable, DataColumnChangeEventArgs)

Event handler

protected virtual void ColumnChanging(MemTable Table, DataColumnChangeEventArgs ea)

Parameters

Table MemTable
ea DataColumnChangeEventArgs

Commit(bool)

Commits changes after an insert or edit. Valid with master modules only.

Returns the row id of the tblItem commited row.

public virtual object Commit(bool Reselect = false)

Parameters

Reselect bool

Returns

object

CommitBatch(BatchCommitArgs)

A Commit() version for batch operations.

Starts a transaction and keeps on calling BeforeFunc while AfterFunc returns true.

Commits the transaction each time the TransLimit is reached.

NOTE: BeforeFunc and AfterFunc are optional.

public virtual void CommitBatch(BatchCommitArgs Args)

Parameters

Args BatchCommitArgs

Commited(bool, object)

Notification method

protected virtual void Commited(bool Reselect, object RowId)

Parameters

Reselect bool
RowId object

Commiting(bool)

Notification method

protected virtual void Commiting(bool Reselect)

Parameters

Reselect bool

ConvertSelectFilterBoolean(object)

Converts a JSON filter value to a boolean SQL value.

protected virtual int ConvertSelectFilterBoolean(object Value)

Parameters

Value object

Returns

int

ConvertSelectFilterValue(object, DataFieldType)

Converts a JSON filter value to the registered filter data type.

protected virtual object ConvertSelectFilterValue(object Value, DataFieldType DataType)

Parameters

Value object
DataType DataFieldType

Returns

object

CreateValidatedSelectFilter(SelectDef, JsonSelectFilter)

Creates a validated SQL filter definition from an active JSON filter.

protected virtual SqlFilterDef CreateValidatedSelectFilter(SelectDef SelectDef, JsonSelectFilter JsonFilter)

Parameters

SelectDef SelectDef
JsonFilter JsonSelectFilter

Returns

SqlFilterDef

CreateValidatedSelectFilters(SelectDef, JsonSelectFilters)

Creates validated SQL filter definitions from active JSON filters.

protected virtual SqlFilterDefs CreateValidatedSelectFilters(SelectDef SelectDef, JsonSelectFilters Filters)

Parameters

SelectDef SelectDef
Filters JsonSelectFilters

Returns

SqlFilterDefs

Delete(object)

Deletes a row. Valid with master modules only.

public virtual void Delete(object RowId)

Parameters

RowId object

Deleted(object)

Notification method

protected virtual void Deleted(object RowId)

Parameters

RowId object

Deleting(object)

Notification method

protected virtual void Deleting(object RowId)

Parameters

RowId object

Edit(object)

Starts an edit operation. Valid with master modules only.

public virtual void Edit(object RowId)

Parameters

RowId object

Edited(object)

Notification method

protected virtual void Edited(object RowId)

Parameters

RowId object

Editing(object)

Notification method

protected virtual void Editing(object RowId)

Parameters

RowId object

EndEdit()

Called from inside Commit(bool).

NOTE: It looks like, in some cases, we have to call EndEdit() for the DataRow(s) to post the changes.

protected virtual void EndEdit()

FindTable(string)

Finds a table by name, if any, else null.

public MemTable FindTable(string TableName)

Parameters

TableName string

Returns

MemTable

GetCodeProviderDef()

Returns the CodeProviderDef

protected virtual CodeProviderDef GetCodeProviderDef()

Returns

CodeProviderDef

GetFilterConditionOps(DataFieldType)

Returns the condition operators supported by a data type.

protected virtual ConditionOp[] GetFilterConditionOps(DataFieldType DataType)

Parameters

DataType DataFieldType

Returns

ConditionOp[]

GetListSelectDef(string)

Returns the select definition for a list select operation.

protected virtual SelectDef GetListSelectDef(string SelectName)

Parameters

SelectName string

Returns

SelectDef

GetNextCodeLocked(DbTransaction)

Returns the next number using an atomic locked increment. Handles reset safely inside the same transaction.

public virtual string GetNextCodeLocked(DbTransaction Transaction)

Parameters

Transaction DbTransaction

Returns

string

GetSelectListRowLimit()

Returns the effective row limit for list SELECTs.

protected virtual int GetSelectListRowLimit()

Returns

int

GetTable(string)

Gets a table by name, if any, else exception.

public MemTable GetTable(string TableName)

Parameters

TableName string

Returns

MemTable

HasChanges()

Returns true if Tripous.Data.TableSet.ItemTable table, or any of its details, in any depth, has changes.

public virtual bool HasChanges()

Returns

bool

Initialize(ModuleDef)

Initializes this instance.

public virtual void Initialize(ModuleDef ModuleDef)

Parameters

ModuleDef ModuleDef

Insert()

Starts an insert operation. Valid with master modules only.

public virtual void Insert()

Inserted()

Notification method

protected virtual void Inserted()

Inserting()

Notification method

protected virtual void Inserting()

JsonApplyTableRows(MemTable, JsonDataModule)

Applies JSON row data to a table and its detail tables.

protected virtual void JsonApplyTableRows(MemTable Table, JsonDataModule Source)

Parameters

Table MemTable
Source JsonDataModule

JsonCommit(JsonDataModule)

Applies a JSON contract object, commits the changes, and returns this data module as a JSON contract object.

public virtual JsonDataModule JsonCommit(JsonDataModule Source)

Parameters

Source JsonDataModule

Returns

JsonDataModule

JsonConvertRowId(string)

Converts a string row id to the key field data type of the item table.

protected virtual object JsonConvertRowId(string Id)

Parameters

Id string

Returns

object

JsonDelete(string)

Deletes an item.

public virtual void JsonDelete(string Id)

Parameters

Id string

JsonEdit(string)

Starts an edit operation and returns this data module as a JSON contract object.

public virtual JsonDataModule JsonEdit(string Id)

Parameters

Id string

Returns

JsonDataModule

JsonInitialize()

Returns this data module as a JSON contract object.

public virtual JsonDataModule JsonInitialize()

Returns

JsonDataModule

JsonInsert()

Starts an insert operation and returns this data module as a JSON contract object.

public virtual JsonDataModule JsonInsert()

Returns

JsonDataModule

JsonSelectList(string, JsonSelectFilters)

Selects the list table and returns it as a JSON contract object.

public virtual JsonDataTable JsonSelectList(string SelectName, JsonSelectFilters Filters)

Parameters

SelectName string
Filters JsonSelectFilters

Returns

JsonDataTable

ListCancel()

Rejects the changes in the list table.

public virtual void ListCancel()

ListSave()

Saves the list table.

public virtual void ListSave()

ListSelect(string)

Selects the list table.

public virtual void ListSelect(string SqlText)

Parameters

SqlText string

ListSelect(SelectDef)

Selects the list table.

public virtual void ListSelect(SelectDef SelectDef)

Parameters

SelectDef SelectDef

LoadDefaultValues()

Loads the default values, such as the default values for fields like CompanyId, CurrencyId, etc.

protected virtual void LoadDefaultValues()

MustReselectAfterCommit()

Notification method

protected virtual bool MustReselectAfterCommit()

Returns

bool

NewRowAdded(MemTable, DataTableNewRowEventArgs)

Event handler

protected virtual void NewRowAdded(MemTable Table, DataTableNewRowEventArgs ea)

Parameters

Table MemTable
ea DataTableNewRowEventArgs

NewRowAdding(MemTable, DataTableNewRowEventArgs)

Event handler WARNING: the new row is not in rows yet

protected virtual void NewRowAdding(MemTable Table, DataTableNewRowEventArgs ea)

Parameters

Table MemTable
ea DataTableNewRowEventArgs

SetAuditDefaultValues(DataTable, DataRow, TableDef)

Sets default values to the Row. It is called when a commit operation starts.

NOTE: This method is called only for the tblItem table.

NOTE: This method sets the CreatedBy, CreatedAt, ModifiedBy, ModifiedAt field values, if they exist in the tblItem.

protected virtual void SetAuditDefaultValues(DataTable Table, DataRow Row, TableDef TableDef)

Parameters

Table DataTable
Row DataRow
TableDef TableDef

SetDefaultValues()

Sets default values for all Tables.

It is called by the DoInsertAfter() and DoCommitBefore()

protected virtual void SetDefaultValues()

SetDefaultValues(DataTable, DataRow, TableDef)

Sets default values to the Row. It is called when a commit operation starts.

protected virtual void SetDefaultValues(DataTable Table, DataRow Row, TableDef TableDef)

Parameters

Table DataTable
Row DataRow
TableDef TableDef

SetDefaultValues(DataTable, TableDef)

Sets default values to the Table. It is called when a commit operation starts.

protected virtual void SetDefaultValues(DataTable Table, TableDef TableDef)

Parameters

Table DataTable
TableDef TableDef

TableExists(string)

True if a table exists, by name.

public bool TableExists(string TableName)

Parameters

TableName string

Returns

bool

TableSet_TransactionStageCommit(object, TransactionEventArgs)

Gets a notification from the TableSet during commit transaction stages.

protected virtual void TableSet_TransactionStageCommit(object sender, TransactionEventArgs e)

Parameters

sender object
e TransactionEventArgs

TableSet_TransactionStageDelete(object, TransactionEventArgs)

Gets a notification from the TableSet when deleting

protected virtual void TableSet_TransactionStageDelete(object sender, TransactionEventArgs e)

Parameters

sender object
e TransactionEventArgs

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string

UpdateTableSchema()

Ensures that any TableDef is updated with the actual table schema from the database.

protected virtual void UpdateTableSchema()