V10 ResourcesReference
ResourcesReference
Reference
Back | List of Articles

How to use the PriGrelha from the PRIMAVERA ERP SDK?

Last changed in 02/12/2020

The SDK is a library of business standards and controls for the PRIMAVERA environment. It allows partners and external development teams to quickly and easily create add-ons for the ERP.

The purse of this article is to describe how we can use one of these controls - the PriGrelha, as well as its loading and initialization process in a database query context (for example, a current account statement list).

Query to execute:

SELECT		TipoEntidade, Entidade, Modulo, Filial, TipoDoc, Serie, NumDocInt, DataDoc, ValorTotal, ValorPendente
FROM		Pendentes
ORDER BY	TipoEntidade, Entidade, DataDoc

Using the PriGrelha

Step 1 - Initializing the SDK

To use any SDK control, it must first be initialized (see article "How to use the ERP PRIMAVERA SDK controls?."

Step 2 - Initialization with the SDK context

After launching the PriGrelha control in the form, it needs to be initialized with the context of the SDK. This initialization must take place before any operation on the table.

private void frmDemoGrid_Load(object sender, EventArgs e)
{
	// Initialize the SDK context
	PriSDKContext.Initialize(BSO, PSO);

	// Initialize SDK controls
	InitializeSDKControls();

	// Initialize the grid
	InitializeGrid();
}

Step 3 - Format

For the table to display results you need to format the respective columns, indicating which field to display for each one. These columns need to comply with the query that will be executed.

The method used for this formatting is AddColKey from the PriGrelha, and these are the main arguments:

ColKeyThe column's unique key
TipoColumn type, which mus match the type of field (Integer, Float, Edit, etc.)
TítuloText that will be displayed in the column header
LarguraWidth of the column
VisívelIndicates whether this column is visible or hidden
CamposBaseDadosDatabase field that will be used to retrieve the results. This can be a calculated value, such as: ValorPago = ValorTotal - ValorPendente
DrillDownIndicates if the column will be formatted for drill-down

In the general initialization of the PriGrelha you also need to indicate other attributes, such as:

  • Groupings
  • Context menu
  • Title
  • Permissions

Groupings

You need to specify if the grid will have groupings and how many are allowed. To do this, you must execute the following command line as many times as the number of groupings you want to allow for the grid (up to a maximum of four):

priGrelha1.AddColAgrupa();

Context menu

By default, the context menu to display will be the standard menu named 'PopupGrelhasStd'. If you want to add new options to the menu, you need to create a specific menu. The instruction to define the context menu is:

priGrelha1.BandaMenuContexto = 'PopupGrelhasStd';

Title

The table must have a title. The instruction to define the title is:

priGrelha1.TituloGrelha = 'Demo Grid 1';

Permissions

There are some properties that indicate what operations are allowed on the table.

PermiteAgrupamentosUserIndicates whether the user can manipulate, create, change or remove the groupings.
PermiteOrdenacaoIndicates whether the user can sort the table
PermiteActualizarIndicates whether the option to update the table data is available
PermiteFiltrosIndicates whether table data filters are available
PermiteDetalhesIndicates whether the lateral details grid is allowed
PermiteStatusBarIndicates whether the status bar is displayed
PermiteDataFillIndicates whether the DataFill event is executed (explained below in this article)
PermiteVistasIndicates whether views for the table data are allowed.

Other table properties

PropertyTypeDescription
BandaMenuContextostringReturns/defines the menu band with user options
BotaoConfigurarActiveBarboolReturns/defines when the column configuration button is available in the internal menu bar
CaminhoTemplateImpressaostringIntenal. File with the printing template
ColsFrozenintNumber of non-editable columns
NumeroMaxRegistosSemPagintMaximum number of records allowed without pagination (the table needs to allow pagination ('Permitir Paginação')
NumeroRegistosintReturns/defines the number of table records
NumLinhasCabecalhointRetorns/defines the number of header lines
OrientacaoMapaenumReturns/sets the orientation of the table for printing
ParentFormModalboolReturns/defines the way context options are presented
PermiteActiveBarboolReturns/defines whether the table's internal menu bar is displayed
PermiteConfigurarDetalhesboolAllows you to retrieve information on whether the details table can be configured
PermiteContextoVaziaboolAllows you to define whether the table allows Right-Click actions when it is empty
PermiteEdicaoboolReturns/defines whether the table allows column editing
PermiteGraficoboolReturns/defines whether the graphics option is available
PermiteGrandeTotalboolReturns/defines whether totalizers are displayed
PermitePaginacaoboolAllows you to activate the table paging when there is a lot of information
PermiteScrollBarsboolReturns/defines if the table adds scroll bars
PosicionaColunaSeguinteboolPlaces the cursor on the next column
TituloGrelhastringReturns/defines the title of the table
TituloMapastringReturns/defines the report title
TypeNameLinhastringAllows you to set the name of the object on the line for MostraBEO and PreencheBEO
TypeNameLinhasstringAllows you to set the name of the object on the lines for MostraBEO and PreencheBEO

Step 4 - Loading the PriGrelha

This article describes the simplest and easiest way to use a PriGrelha in a database query context, through an SQL query executed by DataBind.

As explained above, the fields from the SELECT performed to get records for the table must match the created columns.

The best way to ensure this is by using a method from the table itself to return all fields, following the structure created in the initialization method, which is already correctly formatted to be added to the SELECT.

Example of how to perform the DataBind from a database query:

private void LoadGrid()
{
	StdBELista lista;

	StringBuilder query = new StringBuilder();
	query.AppendLine(string.Format('SELECT {0}', priGrelha1.DaCamposBDSelect()));
	query.AppendLine('FROM Pendentes');
	query.AppendLine(string.Format('WHERE TipoEntidade = '{0}'', tiposEntidade1.TipoEntidade));

	if (!string.IsNullOrWhiteSpace(f41.Text))
	{
		query.AppendLine(string.Format('AND Entidade = '{0}'', f41.Text));
	}

	query.AppendLine('ORDER BY DataDoc');

	lista = new StdBELista();
	lista = PriSDKContext.SdkContext.BSO.Consulta(query.ToString());

	priGrelha1.DataBind(lista);
}

"DataFill" event

If the 'PermiteDataFill' property is enabled, this event will be executed. It allows you to manipulate all the data being loaded into the table, line by line.

private void priGrelha1_DataFill(object Sender, PriGrelha.DataFillEventArgs e)
{
	// Set modulo description
	string modulo = PSO.Utils.FStr(priGrelha1.GetGRID_GetValorCelula(e.Row, colModulo));
	string moduloDesc = modulo;

	switch (modulo)
	{
		case 'V':
			moduloDesc = 'Vendas';
			break;
		case 'C':
			moduloDesc = 'Compras';
			break;
		case 'M':
			moduloDesc = 'C/Corentes';
			break;
		default:
			break;
	}

	priGrelha1.SetGRID_SetValorCelula(e.Row, colModuloDesc, moduloDesc);

	// Set days of delay
	int daysOfDelay = PSO.Utils.FInt(priGrelha1.GetGRID_GetValorCelula(e.Row, colDiasAtraso));
	daysOfDelay = daysOfDelay < 0 ? Math.Abs(daysOfDelay) : 0;
	priGrelha1.SetGRID_SetValorCelula(e.Row, colDiasAtraso, daysOfDelay);
}

Other events

There are other table events. These are the most important ones to consider:

priGrelha1_ActualizaDadosEvent triggered by the table when refresh is clicked
priGrelha1_FormatacaoAlteradaEvent triggered by the table after changes are made to the configuration
priGrelha1_MenuContextoSeleccionadoEvent triggered by the table when a context menu option is clicked

Here you can find a complete example of how to use the PriGrelha in editing mode.

Bookmark or share this article
Esta página foi útil?
Obrigado pelo seu voto.

login para deixar a sua opinião.

Obrigado pelo seu feedback. Iremos analisá-lo para continuarmos a melhorar!
Artigos Relacionados
Características das entidades e serviços Conceito de integração Conceito de extensibilidade Como registar projetos de extensibilidade? Boas práticas de organização de projetos de integração