How to access existing data

99% of the data displayed in the LS One POS/Site Manager systems are open source and available for third party developers.

Access data through the DataProviders project.

The DataProviders project is accessible both from the LS One POS development and the Site Manager development sides. Through this project you have access to all the open source data that is used in both systems.

The data access classes are grouped into different folders based on functionality.

 

You will have to find the class that represents the data object that you are looking for (one trick is to do a text search on the project for the table name).

A typical data access class will give you access to the following methods:

Typical data access functions

Description

DataObject Get(
IConnectionManager entry, RecordIdentifier Id)

 

Gets a single instance of your data object with the given ID. 

List<DataObject> GetList(
IConnectionManager entry)

 

Gets a list of all instances of the data object in the system.

void Save(
IConnectionManager entry, DataObject dataObject)

 

Saves an instance of the data object to the database.

void Delete(
IConnectionManager entry, RecordIdentifier id)

 

Deletes an instance of your data object with the given ID from the database.

IConnectionManager entry

Every data access function requires parameters of type IConnectionManager. This parameter is your access point to the database. It tells the Site Manager where the database is and gives it necessary information about it.

You get this value in the PluginEntry class Init(..) function.

Init(IConnectionManager dataModel, IApplicationCallbacks frameworkCallbacks)

So you have to store the dataModel variable and then pass it to all your data access functions.

Example

In the Criminal plugin code we use existing data access objects. In the Criminal plugin, go to Dialogs/StolenItemDialog.cs

In this dialog we are adding a stolen item to a criminal. To do this we have to get a list of units and stores.

We fetch all of this information when we fetch data into our combo boxes and this is the code:

private void cmbUnit_RequestData(object sender, EventArgs e)
{
	cmbUnit.SetData(Providers.UnitData.GetList(PluginEntry.DataModel), null);
}

private void cmbStore_RequestData(object sender, EventArgs e)
{
	cmbStore.SetData(Providers.StoreData.GetList(PluginEntry.DataModel), null);
}

In both functions, we start by using the DataProviders class to access all DataProviders and fetch a list of data objects which we then display in the drop down menu. The PluginEntry.DataModel represents the IConnectionManager saved in the Init function.

 

Next you learn to add or edit the database : How to create/edit a database table