V10 ResourcesGuides
ResourcesGuides
Guides
Back | List of Articles

How to add new tabs to the ERP Ribbon with Visual Studio?

Last changed in 02/11/2021

This document describes the steps necessary to add new menus to the ERP ribbon. This mechanism is an alternative to the using user menus, as it gives the organization total control over the several options of the external application. This allows for the creation of multiple tabs and groups that enable you to organize operations according to their function.

Unlike user menus, operations created with this technology do not implement the ERP security mechanism automatically, which means it is not possible for the administrator to define by profile who has access to the operations. To overcome this situation it is necessary to create an administrator extensibility project and define permissions for the operations available in the ribbon.

This option is the most suitable when you want to create an extension that adds a new functional area to the ERP, without being dependent on creating user menus manually.

Requirements

  • ERP PRIMAVERA
  • Visual Studio & .NET Framework 4.7

Step 1 - Create the project

1 - After opening Visual Studio, select File > New > Project.
2 - In the window on the left, choose your development language (C# or VB)
3 - Select the Class Library (.NET Framework) project type.
4 - Assign a name to the 'Primavera.CustomRibbon' project and press OK.
5 - Select the project properties and, under Project > Properties > Resources add an image for the button.

Step 2 - References

After creating the project, you need to add a set of references to the extensibility platform. This will allow you to subscribe the DepoisDeCriarMenus event, exposed by the platform, which will be used to build the new menu.

  • PrimaveraExtensibility.BusinessEntities.
  • Primavera.Extensibility.Integration
  • Primavera.Extensibility.Platform
  • StdPlatBS100

Step 3 - Create the ribbon

1 - Rename the class from 'Class1.cs' to 'PrimaveraRibbon.cs'
2 - Add the following namespaces at the beginning of the class, using the using instruction.
3 - After the class name add Plataforma. This step indicates that our class will inherit all methods, properties and attributes from the Plataforma base class.

 width=

4 - In the body of the created class write override and press TAB. A list will be displayed with all the events you can subscribe. In this case, select the DepoisDeCriarMenus event and add the following code:

using System;
using System.Diagnostics;
using System.Drawing;
using Primavera.Extensibility.BusinessEntities.ExtensibilityService.EventArgs;
using Primavera.Extensibility.Platform.Services;
using StdPlatBS100;

namespace Primavera.CustomRibbon
{
    public class PrimaveraRibbon : Plataforma
    {
	const string cIDTAB = "10000";
	const string cIDGROUP = "100001";
	const string cIDBUTTON1 = "1000011";
	const string cIDBUTTON2 = "1000012";

        private StdBSPRibbon RibbonEvents;

        ///
        /// This event will execute for all ribbon changes.
        ///

///
public override void DepoisDeCriarMenus(ExtensibilityEventArgs e)
{
// Register the Ribbon events.
RibbonEvents = this.PSO.Ribbon;
RibbonEvents.Executa += RibbonEvents_Executa;

// Create a new TAB.
this.PSO.Ribbon.CriaRibbonTab("TAB", cIDTAB, 10);

// Create a new Group.
this.PSO.Ribbon.CriaRibbonGroup(cIDTAB, "Group 1", CIDGROUP01);

// Create a new 32x32 Button.
this.PSO.Ribbon.CriaRibbonButton(cIDTAB, CIDGROUP, cIDBUTTON1, "My Button", true, Resource.button1);
}

///

        /// Ribbon events.
        ///

///
///
private void RibbonEvents_Executa(string Id, string Comando)
{
try
{
switch (Id)
{
case CIDBUTTON1:
//Call action.
break;
}
}
catch (System.Exception ex)
{
PSO.MensagensDialogos.MostraAviso("Fail to execute the command.",StdBSTipos.IconId.PRI_Informativo,ex.Message);
}
}
}
}

5. Compile your solution in BUILD > Build Solution.

6 - Register the assembly as described in 'How to register extensibility projects?'

Step 4 - Permissions for operations

With the Administrator's extensibility technology you can define permissions for the application's operations and whether the user has access to the selected operation.

Validate operation permissions

private void RibbonEvents_Executa(string Id, string Comando)
{
	switch (Id)
	{
	case CIDBUTTON1:
		if (Plataforma.Contexto.Utilizador.AcedeOperacao('EXT', 'mnuOperacao1'))
		{
			//Call action.
		}	
		break;
	}
}

Validate dynamic permissions

private void RibbonEvents_Executa(string Id, string Comando)
{
	switch (Id)
	{
	case CIDBUTTON1:
		if (Plataforma.Contexto.Utilizador.AcedeAtributo('Documento', 'FA', 'EXT', 'CRIAR'))
		{
			//Call action.
		}	
		break;
	}
}
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?