V10 ResourcesReference
ResourcesReference
Reference
Back | List of Articles

How to use SDK's PriGrelha in edit mode?

Last changed in 02/07/2020

The SDK is a library of business standards and controls for the PRIMAVERA environment, that offers a set of components in order to offer the third-party applications the same level of features and user experience as the ERP.

When developing business applications, grids are often used to insert data that. Depending on the use context, can require the implementation of several features' existent in the ERP, such as, drilldown, printing, column configuration, etc.

In these cases, it is recommended to use the grid provided in the SDK, considering that it allows to refrain the development teams from the referred implementations and allow them to focus on the client's business.

Configure grids

In the next steps, we describe how to configure the grit in the data insertion context.

Step 1 - Initializations

First, it is necessary to initialize the SDK context. For more information, please see the article "How to use the PRIMAVERA ERP SDK controls?."

To use the PriGrelha in consultation mode, for example in an exploration, we suggest viewing the article "How to use the PRIGRELHA from the PRIMAVERA ERP SDK?"

The initialization process in edit mode is similar and the differences between the PriGrelha in edit and consultation mode will be explained later.

Step 2 - Column and properties definition

When started in consultation mode, the grid does not present the same behavior as in the editing mode, so you should consider a few properties when defining the columns.

Similarly, you should pay additional attention to the definition of the column type, considering that there is a dependency relation between the column type and the data inserted in the cells.

You should also consider a few grid properties, namely, the property that defines the editing mode.

Columns properties

BloqueadaIndicates if the cells are locked for editing.
ValorMinimoMinimum value each column cell can assume (applicable to numeric cells).
ValorMaximoMaximum value each column cell can assume (applicable to numeric cells).
CasasDecimaisNo. of decimal places.
EditLenCell writing size (applicable to text cells).
ComboValoresValues for the items of the cell type "combobox" (explained later).

Column Types

CellTypeDateFor cells that accepted values referring to dates.
CellTypeEditFor cells that accepted free text.
CellTypeStaticTextFor cells that show free, but non-editable text.
CellTypeIntegerFor cells that accepted integer numeric values.
CellTypeFloatFor cells that accept decimal numeric values.
CellTypeComboBoxCells formatted with combobox.
CellTypeCheckBoxCells formatted with checkbox.

Grid properties

PermiteEdicaoIndicates if the grid is in editing mode (true).
PermiteAgrupamentosUserIn editing mode, there are no groupings (false).
PermiteDataFillIn editing mode, the grid loading is never performed by DataBind (false).
PermiteFiltrosIn editing mode, the filters are also not active (false).

Cells of the ComboBox Type

The cells of the ComboBox require a special handling because they need to load the items to be shown in the combo.

Thus, when defining the columns in the AddColKey you should indicate the items through the ComboValores argument.

The following example shows how to load the items "Cliente" (Client), "Fornecedor" (Supplier) and "Outro Terceiro" (Other Third-Party) for the combo, in the column you wish the user to choose the entity type from:

priGrelha1.AddColKey(colTipoEntidade, FpCellType.CellTypeComboBox, "Tipo Ent.", 8, strComboValores: DaValoresComboTipoEntidade());

private string DaValoresComboTipoEntidade()
{
	return
		"Clientet" +
		"Fornecedort" +
		"Outro Terceiro";
}

To read the selected item value, you should use a normal cell value reading method, and the read value correspond to the selection index.

The following example shows the reading of the value and its conversion to the known entity type:

private string GetTipoEntidadeFromGrid(int row)
{
	string result = "C";

	switch (PSO.Utils.FInt(priGrelha1.GetGRID_GetValorCelula(row, colTipoEntidade)))
	{
		case 1:
			result = "F";
			break;
		case 2:
			result = "O";
			break;
		default:
			break;
	}

	return result;
}

To assign a value to a cell of this type, you should use the native grid method, and this value should be from the combobox item itself:

private void SetValorComboboxGrelha(string col, int row, string value)
{
	//Updates the combo value in the grid.
	priGrelha1.Grelha.SetText(priGrelha1.Cols.GetEdita(col).Number, row, value);
}

Step 3 - Reading and writing values

Method to read the value in a cell:

priGrelha1.GetGRID_GetValorCelula(row, colNomeColuna);

Method to write a value in a cell:

priGrelha1.SetGRID_SetValorCelula(row, colNomeColuna, "Valor");

Step 4 - Invoke the lists in the rows using F4 

The following example shows how the item list is presented when you wish to select a specific item. You should invoke a list from the KeyDown event from the grid.

private void priGrelha1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
	try
	{
		if (e.KeyCode == Keys.F4 && !e.Control && !e.Shift)
		{
			TrataF4Linhas(priGrelha1.Grelha.ActiveCol, priGrelha1.Grelha.ActiveRow);
		}

		return;
	}
	catch (Exception ex)
	{
		PSO.Dialogos.MostraErroSimples("Erro ao executar a operação!", StdPlatBS100.StdBSTipos.IconId.PRI_Critico, ex.Message);
	}
}

private void TrataF4Linhas(int col, int row)
{
	// Items
	if (col == priGrelha1.Cols.GetEdita(colArtigo).Number)
	{
		PSO.AbreLista(1, ConstantesPrimavera100.Categorias.Artigo, "Artigo", this, priGrelha1.Grelha, "mnuTabArtigo", row, col, false, "(ArtigoAnulado = 0)");
	}
}

When a list is invoked, the AbreLista receives the form, a grid, column and current row as an argument.

Thus, when invoking the list using F4 key, the system records the item selected by the user in the previous window field.

The value in inserted in the grid and, if it exists, the method F4RowFileds is automatically invoked.

In this method, you should insert the necessary code to execute when a list item is selected.

public void F4RowFields(string Categoria, string NomeCampo, dynamic Valor)
{
	try
	{
		if (Categoria == ConstantesPrimavera100.Categorias.Artigo)
		{
			TrataColuna_Artigo(priGrelha1.Grelha.ActiveRow);
		}
	}
	catch (Exception ex)
	{
		PSO.Dialogos.MostraErro("Erro ao carregar o registo.", StdPlatBS100.StdBSTipos.IconId.PRI_Exclama, ex.Message, ex);
	}
}

private void TrataColuna_Artigo(int row)
{
	try
	{
		string artigo = PSO.Utils.FStr(priGrelha1.GetGRID_GetValorCelula(row, colArtigo));

		if (!string.IsNullOrWhiteSpace(artigo))
		{
			if (BSO.Base.Artigos.Existe(artigo))
			{
				BasBEArtigo beArtigo = BSO.Base.Artigos.Consulta(artigo);

				priGrelha1.SetGRID_SetValorCelula(row, colArtigo, beArtigo.Artigo.ToUpper());
				priGrelha1.SetGRID_SetValorCelula(row, colDescArtigo, beArtigo.Descricao.ToUpper());
			}
			else
			{
				throw new Exception("Artigo inexistente!");
			}
		}
	}
	catch (Exception ex)
	{
		priGrelha1.SetGRID_SetValorCelula(row, priGrelha1.Cols.GetEdita(colArtigo).ColKey, string.Empty);
		priGrelha1.SetGRID_SetValorCelula(row, priGrelha1.Cols.GetEdita(colDescArtigo).ColKey, string.Empty);
		
		throw ex;
	}
}

Step 5 - EditMode Event

The EditMode event is activated when the user is in edit mode in a cell, as well as when he finishes it.

You should execute the same procedure as F4, that is, validate the inserted value, fill in other related data, etc.

private void priGrelha1_EditMode(object Sender, PriGrelha.EditModeEventArgs e)
{
	try
	{
		if ((e.Mode == 0) && (e.ChangeMade))
		{
			TrataColuna(e.Col, e.Row);
		}
	}
	catch (Exception ex)
	{
		PSO.Dialogos.MostraErroSimples("Erro ao executar a operação!", StdPlatBS100.StdBSTipos.IconId.PRI_Critico, ex.Message);
	}
}

private void TrataColuna(int col, int row)
{
	if ((row > priGrelha1.Grelha.DataRowCnt) || row == 0)
	{
		return;
	}

	if (col == priGrelha1.Cols.GetEdita(colArtigo).Number)
	{
		TrataColuna_Artigo(row);
	}
}

Step 6 - Other methods and grid events to consider

Methods

InsereLinhasInserts n rows from the specified position.
RemoveLinhasRemoves n rows from the specified position.
AdicionaLinhasBrancoGrelhaEdicaoAdds 50 rows to the existent rows so that they are editable.
FormataLinhaEdicaoFormats all one row columns for editing.
GRID_InsereLinhaEdicaoInserts a row for editing.
GRID_RemoveLinhaEdicaoRemoves a row for editing.
Grid_BloqueiaColunaLocks/unlocks one or more cells.
Grid_BloqueiaLinhaLocks/unlocks the cells for one or more rows.
Grid_CelulaBloqueadaIndicates if the cell is locked.
Grid_EscondeLinhaHides/shows one or more rows.
Grid_LimpaParteDaGrelhaClears one or more cells.
Grid_SetActiveCellPositions the mouse cursor on a grid cell.
PosicionaCelulaAnteriorPositions the mouse cursor in the previous cell.
PosicionaCelulaSeguintePositions the mouse cursor in the following cell.

Events

AntesInserirLinhaOccurs before GRID_InsereLinhaEdicao()
AntesRemoverLinhaOccurs before GRID_RemoveLinhaEdicao()
LinhaInseridaOccurs after GRID_InsereLinhaEdicao()
LinhaRemovidaOccurs after GRID_RemoveLinhaEdicao()

In here you can find a complete example of how to use the PriGrelha in edit 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
Últimos Artigos Vistos
How to register extensions automatically?