Class DataModule
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
TableSet
Field
protected TableSet TableSet
Field Value
fIsCommiting
Field
protected int fIsCommiting
Field Value
fIsDeleting
Field
protected int fIsDeleting
Field Value
fIsEditing
Field
protected int fIsEditing
Field Value
fIsInserting
Field
protected int fIsInserting
Field Value
fStocks
Field
protected List<MemTable> fStocks
Field Value
fVariables
Field
protected Dictionary<string, object> fVariables
Field Value
Properties
CodeProviderDef
The code provider definition.
public CodeProviderDef CodeProviderDef { get; protected set; }
Property Value
CurrentRow
Returns the first row of the tblItem.
WARNING: Valid only in insert and edit mode.
public virtual DataRow CurrentRow { get; }
Property Value
DataSet
The DataSet of the module.
public DataSet DataSet { get; protected set; }
Property Value
DetailsActive
When true then detail relationships are active.
public bool DetailsActive { get; set; }
Property Value
Id
Returns the value of the Id field of the tblItem
public virtual object Id { get; }
Property Value
IsCommiting
True while commiting, that is while Commit() executes.
public bool IsCommiting { get; protected set; }
Property Value
IsDeleting
True while deleting, that is while Delete() executes.
public bool IsDeleting { get; protected set; }
Property Value
IsEditing
True while loading, that is while Edit() executes.
public bool IsEditing { get; protected set; }
Property Value
IsInitialized
True if the module is initialized.
public bool IsInitialized { get; }
Property Value
IsInserting
True while inserting, that is while Insert() executes.
public bool IsInserting { get; protected set; }
Property Value
this[string]
An indexer with all tables
public MemTable this[string TableName] { get; }
Parameters
TableNamestring
Property Value
LastCommitedId
Returns the Id of the last commit
public object LastCommitedId { get; protected set; }
Property Value
LastDeletedId
Returns the Id of the last delete
public object LastDeletedId { get; protected set; }
Property Value
LastEditedId
Returns the id of the item the last Edit() operation has loaded
public object LastEditedId { get; protected set; }
Property Value
ModuleDef
The module definition.
public ModuleDef ModuleDef { get; protected set; }
Property Value
Name
The name of this module
public string Name { get; }
Property Value
RowProviderHost
The row provider host of this module. Typically the tblItem
public IRowProviderHost RowProviderHost { get; }
Property Value
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
Stocks
The stock tables.
public List<MemTable> Stocks { get; }
Property Value
Store
The SqlStore instance."/>
public SqlStore Store { get; protected set; }
Property Value
Tables
All tables, tblList included.
public IEnumerable<MemTable> Tables { get; }
Property Value
Variables
Gets the variables of the module.
public Dictionary<string, object> Variables { get; protected set; }
Property Value
tblItem
The top table of the table tree. Is always a single-row table.
public MemTable tblItem { get; protected set; }
Property Value
tblList
The list table, the one that has the list SELECT data
public MemTable tblList { get; protected set; }
Property Value
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
TransactionDbTransaction
BatchInsert(DataTable)
Inserts rows from a source table using batch commit.
public virtual void BatchInsert(DataTable tblSource)
Parameters
tblSourceDataTable
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
SelectNamestringFiltersJsonSelectFiltersSelectDefSelectDef
Returns
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
Reselectbool
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
RowIdobject
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
RowIdobject
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
TableMemTableeaDataColumnChangeEventArgs
ColumnChanging(MemTable, DataColumnChangeEventArgs)
Event handler
protected virtual void ColumnChanging(MemTable Table, DataColumnChangeEventArgs ea)
Parameters
TableMemTableeaDataColumnChangeEventArgs
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
Reselectbool
Returns
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
ArgsBatchCommitArgs
Commited(bool, object)
Notification method
protected virtual void Commited(bool Reselect, object RowId)
Parameters
Commiting(bool)
Notification method
protected virtual void Commiting(bool Reselect)
Parameters
Reselectbool
ConvertSelectFilterBoolean(object)
Converts a JSON filter value to a boolean SQL value.
protected virtual int ConvertSelectFilterBoolean(object Value)
Parameters
Valueobject
Returns
ConvertSelectFilterValue(object, DataFieldType)
Converts a JSON filter value to the registered filter data type.
protected virtual object ConvertSelectFilterValue(object Value, DataFieldType DataType)
Parameters
ValueobjectDataTypeDataFieldType
Returns
CreateValidatedSelectFilter(SelectDef, JsonSelectFilter)
Creates a validated SQL filter definition from an active JSON filter.
protected virtual SqlFilterDef CreateValidatedSelectFilter(SelectDef SelectDef, JsonSelectFilter JsonFilter)
Parameters
SelectDefSelectDefJsonFilterJsonSelectFilter
Returns
CreateValidatedSelectFilters(SelectDef, JsonSelectFilters)
Creates validated SQL filter definitions from active JSON filters.
protected virtual SqlFilterDefs CreateValidatedSelectFilters(SelectDef SelectDef, JsonSelectFilters Filters)
Parameters
SelectDefSelectDefFiltersJsonSelectFilters
Returns
Delete(object)
Deletes a row. Valid with master modules only.
public virtual void Delete(object RowId)
Parameters
RowIdobject
Deleted(object)
Notification method
protected virtual void Deleted(object RowId)
Parameters
RowIdobject
Deleting(object)
Notification method
protected virtual void Deleting(object RowId)
Parameters
RowIdobject
Edit(object)
Starts an edit operation. Valid with master modules only.
public virtual void Edit(object RowId)
Parameters
RowIdobject
Edited(object)
Notification method
protected virtual void Edited(object RowId)
Parameters
RowIdobject
Editing(object)
Notification method
protected virtual void Editing(object RowId)
Parameters
RowIdobject
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
TableNamestring
Returns
GetCodeProviderDef()
Returns the CodeProviderDef
protected virtual CodeProviderDef GetCodeProviderDef()
Returns
GetFilterConditionOps(DataFieldType)
Returns the condition operators supported by a data type.
protected virtual ConditionOp[] GetFilterConditionOps(DataFieldType DataType)
Parameters
DataTypeDataFieldType
Returns
GetListSelectDef(string)
Returns the select definition for a list select operation.
protected virtual SelectDef GetListSelectDef(string SelectName)
Parameters
SelectNamestring
Returns
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
TransactionDbTransaction
Returns
GetSelectListRowLimit()
Returns the effective row limit for list SELECTs.
protected virtual int GetSelectListRowLimit()
Returns
GetTable(string)
Gets a table by name, if any, else exception.
public MemTable GetTable(string TableName)
Parameters
TableNamestring
Returns
HasChanges()
Returns true if Tripous.Data.TableSet.ItemTable table, or any of its details, in any depth, has changes.
public virtual bool HasChanges()
Returns
Initialize(ModuleDef)
Initializes this instance.
public virtual void Initialize(ModuleDef ModuleDef)
Parameters
ModuleDefModuleDef
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
TableMemTableSourceJsonDataModule
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
SourceJsonDataModule
Returns
JsonConvertRowId(string)
Converts a string row id to the key field data type of the item table.
protected virtual object JsonConvertRowId(string Id)
Parameters
Idstring
Returns
JsonDelete(string)
Deletes an item.
public virtual void JsonDelete(string Id)
Parameters
Idstring
JsonEdit(string)
Starts an edit operation and returns this data module as a JSON contract object.
public virtual JsonDataModule JsonEdit(string Id)
Parameters
Idstring
Returns
JsonInitialize()
Returns this data module as a JSON contract object.
public virtual JsonDataModule JsonInitialize()
Returns
JsonInsert()
Starts an insert operation and returns this data module as a JSON contract object.
public virtual JsonDataModule JsonInsert()
Returns
JsonSelectList(string, JsonSelectFilters)
Selects the list table and returns it as a JSON contract object.
public virtual JsonDataTable JsonSelectList(string SelectName, JsonSelectFilters Filters)
Parameters
SelectNamestringFiltersJsonSelectFilters
Returns
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
SqlTextstring
ListSelect(SelectDef)
Selects the list table.
public virtual void ListSelect(SelectDef SelectDef)
Parameters
SelectDefSelectDef
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
NewRowAdded(MemTable, DataTableNewRowEventArgs)
Event handler
protected virtual void NewRowAdded(MemTable Table, DataTableNewRowEventArgs ea)
Parameters
TableMemTableeaDataTableNewRowEventArgs
NewRowAdding(MemTable, DataTableNewRowEventArgs)
Event handler WARNING: the new row is not in rows yet
protected virtual void NewRowAdding(MemTable Table, DataTableNewRowEventArgs ea)
Parameters
TableMemTableeaDataTableNewRowEventArgs
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
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
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
TableExists(string)
True if a table exists, by name.
public bool TableExists(string TableName)
Parameters
TableNamestring
Returns
TableSet_TransactionStageCommit(object, TransactionEventArgs)
Gets a notification from the TableSet during commit transaction stages.
protected virtual void TableSet_TransactionStageCommit(object sender, TransactionEventArgs e)
Parameters
senderobjecteTransactionEventArgs
TableSet_TransactionStageDelete(object, TransactionEventArgs)
Gets a notification from the TableSet when deleting
protected virtual void TableSet_TransactionStageDelete(object sender, TransactionEventArgs e)
Parameters
senderobjecteTransactionEventArgs
ToString()
Returns a string representation of this instance.
public override string ToString()
Returns
UpdateTableSchema()
Ensures that any TableDef is updated with the actual table schema from the database.
protected virtual void UpdateTableSchema()