V10 ResourcesGuides
ResourcesGuides
Guides
Back | List of Articles

How to open lists in external applications?

Last changed in 02/07/2020

The listas PRIMAVERA ERP mechanism is, probably, the most popular feature of the system, because it allows to access and explore the information stored for the operations available in the application Shell. On the other hand, the lists also allow to edit system records and it is possible in the Shell, using the "F4" key, to call a client list and select the record to be edited.

Open ERP list

Next, we will demonstrate how to open an ERP list from an external application, correctly connected to an information category.

Step 1 - Create the project and add the necessary references

In Visual Studio we start by creating a simple Windows Forms App project (.NET Framework) by adding the following ERP references:

  • ERPBS100
  • StdBE100
  • StdBE100
  • StdBSSql100
  • StdPlatBE100
  • StdPlatBS100
  • Primavera.Extensibility.Engine
  • Primavera.Extensibility.Paterns

Step 2 - Initializing the platform and work company

Before performing any operation on the ERP, it is necessary to open the platform and the work company using the following method:

private ErpBS100.ErpBS BSO { get; set; }
private StdPlatBS100.StdPlatBS PSO { get; set; }

private void CreateContextERP()
{
	PSO = new StdPlatBS100.StdPlatBS();
	BSO = new ErpBS100.ErpBS();

	StdPlatBS100.StdBSConfApl objAplConf = new StdPlatBS100.StdBSConfApl
	{
		Instancia = _Instancia,
		AbvtApl = "ERP",
		PwdUtilizador = _Password,
		Utilizador = _Utilizador,
		LicVersaoMinima = "10.00"
	};

	StdBE100.StdBETransaccao objStdTransac = new StdBE100.StdBETransaccao();

	EnumTipoPlataforma TipoPlataforma = EnumTipoPlataforma.tpEmpresarial;

	try
	{
		PSO.AbrePlataformaEmpresa(_Company, objStdTransac, objAplConf, TipoPlataforma);
	}
	catch (Exception ex)
	{
		throw (ex);
	}

	if (PSO.Inicializada)
	{
		BSO.AbreEmpresaTrabalho(TipoPlataforma, _Company, _Utilizador, _Password, objStdTransac, _Instancia);
	}
}

Step 3 - AbreLista event

In the Shell, when a F4 control invokes the corresponding list (pressing the F4 key), the event AbreLista of the class StdBSNavegador (assembly StdPlatBS100) is triggered. To be able to control the list on the external application, it is necessary to subscribe the evento (ideally, in the class load).

private StdPlatBS100.StdBSNavegador Navegador = null;

Navegador = PSO.Navegador;
Navegador.AbreLista += new StdPlatBS100.StdBSNavegador.AbreListaHandler(Navegador_AbreLista);

The event, already subscribed on the external application, must first validate if the user has permission for the selected category and then open the corresponding list.

public void Navegador_AbreLista(StdPlatBE100.StdBEF4 ObjF4, StdBSSql100.StdBSOSQL SqlBSO, StdBESql100.StdBESqlQuery Query, StdBE100.StdBECampos Filtro)
{
	// Does the user have permission on the category?
	if ((!PSO.Categorias.TestaPermissaoLista(Query.Categoria, Query.Query, Query.Utilizador, Query.Sistema, StdPlatBE100.StdBETipos.TipoPermissaoListas.tplstConsultar)))
	{
		return;
	}

	// Does the user have permission to view the list?
	TrataNavegadorAbreLista(ObjF4, SqlBSO, Query, Filtro);
}

Step 4 - List opening

As shown previously, when the event is triggered, the method TrataNavegadorAbreLista is invoked. In here, it is handled in order to open the list. First, it is necessary to declare a property of the StdBELista public type, with the name Lista. This property will be used when starting the list.

public StdPlatBS100.StdBSLista Lista { get; set; } = null;

The event AbreLista receives, in its parameter, besides the query and the filter, the control that invoked the list. This control must be assigned to the corresponding FormLista property. It is also necessary to validate if the form is modal or not. If it is modal, the list will also be presented in the same way.

private void TrataNavegadorAbreLista(StdPlatBE100.StdBEF4 ObjF4, StdBSSql100.StdBSOSQL SqlBSO, StdBESql100.StdBESqlQuery Query, StdBE100.StdBECampos Filtro)
{
	StdPlatBS100.frmLista fFormLista = null;

	var bF4 = false;
	var bModal = false;

	if (ObjF4 != null)
	{
		bF4 = true;
		bModal = ObjF4.Modal;
	}

	if (bF4)
	{
		if (bModal || fFormLista == null)
		{
			//F4 Modal
			fFormLista = PSO.Dialogos.DaDialogoListas();
			PSO.Menus.ClasseBase = this;
			fFormLista.F4 = (ObjF4 != null);
			fFormLista.F4Ctrl = ObjF4;
			fFormLista.Inicializa(this, Query, Filtro);

                        // The show must be performed outside Inicializa 
			fFormLista.ShowDialog();                                               

			if (!ObjF4.FormF4.TopLevel)
			{
				ObjF4.FormF4.Parent.FindForm()?.BringToFront();
			}
			else
			{
				ObjF4.FormF4.BringToFront();
			}
		}
		else
		{
			// ZOrder is now executed only when the list is not modal
			fFormLista.BringToFront();
		}
	}
	else
	{
		fFormLista.BringToFront();
	}
}

Step 5 - List opening

Add a control of the type TextBox and in the event button click, it is only necessary to insert the following line:

PSO.Listas.TrataF4("Clientes", "Cliente", this, textBoxCliente, "mnuTabClientes");

The category moves to TrataF4 (1st parameter) can be retrieved by the constants in the assembly ConstantesPrimavera100 and class Categories. This way, the audit name is in constants in the class Audit.

PSO.Listas.TrataF4(ConstantesPrimavera100.Categorias.Cliente, "Cliente", this, textBoxCliente, ConstantesPrimavera100.Audit.TAB_CLIENTES);

A practical example of the use of this technique is available on Github.

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
Começar a Usar Como criar um projeto de integração com Visual Studio? Como criar um projeto de extensibilidade de interface (PEX) com Visual Studio? Como criar um projeto de extensibilidade de API (Motor) com Visual Studio? Como criar separadores do utilizador com Visual Studio?