V10 ResourcesGuides
ResourcesGuides
Guides
Back | List of Articles

How to create related information panels with Visual Studio?

Last changed in 02/12/2020

This document describes the necessary steps for creating related information panels for the PRIMAVERA ERP in Visual Studio. Related information panels function as containers where you can components with information related to a category.

Requirements

  • PRIMAVERA ERP
  • Visual Studio & .NET Framework 4.7

To illustrate this procedure, let's consider the example of creating a component to display the value of a customer's or supplier's current account. This information will be displayed in the context of the sales editor.

Step 1 - Create the project

1 - After opening Visual Studio, select File > New > Project.

2 - From the tree on the left of the displayed window select the 'C#' development language;

3 - Select the Class Library (.NET Framework) project type.

4 - Rename the project as 'Primavera.RelatedInfo' and press OK.

5 - Add a 'User Control' to the project and rename it to 'CurrentAccountInfo'.

6 - Add a new folder to the project and name it 'DB'. This folder will be used to save the SQL code that will later be used to register the control in the system.

7 - In the 'DB' folder add an empty file and name it 'Register_Related_Info.sql'.

At the end of this step your project should look similar to this:

 width=


Step 2 - Register the component in the database

1 - Add the following code in the 'Register_Related_Info.sql' file:

DELETE  from ContextosInformacaoRelacionada WHERE [IdCategoria]='8701B2DD-3FA4-4874-9E6E-E4195734FF22'
DELETE  from InformacaoRelacionada WHERE [Id]='8701B2DD-3FA4-4874-9E6E-E4195734FF22'
GO

INSERT INTO InformacaoRelacionada ([Id],[Categoria],[Config]) 
Values(
	'8701B2DD-3FA4-4874-9E6E-E4195734FF22',
	'Clientes',
	'
    
        Primavera.RelatedInfo.CurrentAccountInfo
        Pendente por entidade
        
        Saldo em divida por conta
        0
        200
    
	'
)
GO


INSERT INTO ContextosInformacaoRelacionada([IdCategoria],[Contexto],[Ordem],[Params]) 
Values (
	'8701B2DD-3FA4-4874-9E6E-E4195734FF22',
	'frmDocVendas',1,
	'
		
	        1
	    
	    
	'
)
GO

2 - Connect to the database server, choose the type of connection and authentication mode.

3 - Select the company and execute.

Step 3 - Implement the panel

1 - After creating the project you need to add references to the StdBE100 and StdPlatBE100 assemblies.

2 - Add the following namespaces at the beginning of the 'CurrentAccountInfo' class,using the using method:

  • StdBE100
  • StdPlatBE100

3 - After the control name add 'IStdBEInfRelacionada'. This step indicates that the 'CurrentAccountInfo' class will inherit from the 'IStdBEInfRelacionada' interface.

4 - After implementing the IStdBEInfRelacionada interface, your project should look similar to this:

 width=

5 - You can now implement the 'CurrentAccountInfo' class by adding the following code:

using StdBE100;
using StdPlatBE100;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;

namespace Primavera.RelatedInfo
{
    ///
    /// This component will display the party (customer or supplier) current account amount.
    /// The information will be displayed on the sales editor context.
    /// The trigger will be caused when customer field change.
    ///
    public partial class CurrentAccountInfo : UserControl, IStdBEInfRelacionada
    {
        #region Public methods

        public CurrentAccountInfo()
        {
            InitializeComponent();
        }

        #endregion

        #region private variables

        private StdBECategoryInfo categoryInfo;
        private dynamic formContext;
        private dynamic plataform;
        private dynamic engine;

        #endregion

        #region Private properties

        private string EntityKey { get; set; }

        #endregion

        #region Private Methods

        ///
        /// Fill the grid with the selected entity account amount.
        ///
        void LoadGrid()
        {
            StringBuilder sql = new StringBuilder();
            string query = string.Empty;

            // Get the connection string from the context.
            string connectionString = plataform.BaseDados.DaConnectionStringNET
            (plataform.BaseDados.DaNomeBDdaEmpresa(engine.Contexto.CodEmp), 'Default');

            sql.Append('SELECT TipoDoc,TipoConta, SUM(ValorPendente) AS Total , SUM(Valortotal) AS Pendente FROM');
            sql.Append(' Pendentes WHERE entidade='@1@'');
            sql.Append(' GROUP BY TipoConta,TipoDoc');

            query = sql.ToString();
            query = query.Replace('@1@', this.EntityKey);

            try
            {
                dataGridPendentes.ReadOnly = true;

                SqlConnection connection = new SqlConnection(connectionString);
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                SqlCommandBuilder comBuilder = new SqlCommandBuilder(dataAdapter);

                DataSet ds = new DataSet();

                dataAdapter.Fill(ds);
                dataGridPendentes.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        #endregion

        #region _IStdBEInfRelacionada Members

        ///

        /// This is the bound category info.
        ///
        StdBECategoryInfo IStdBEInfRelacionada.BECategoryInfo
        {
            get
            {
                return this.categoryInfo;
            }
            set
            {
                this.categoryInfo = value;
            }
        }

        ///

        /// This active ERP engine.
        ///
        dynamic IStdBEInfRelacionada.MotorAplicacao
        {
            set
            {
                this.engine = value;
            }
        }

        ///

        /// The active ERP platform.
        ///
        dynamic IStdBEInfRelacionada.Plataforma
        {
            set
            {
                this.plataform = value;
            }
        }

        ///

        /// This is the context form.
        ///
        dynamic IStdBEInfRelacionada.FormContexto
        {
            set
            {
                this.formContext = value;
            }
        }

        ///

        /// This is the bound category value.
        ///
        void IStdBEInfRelacionada.AdicionaChave(string Nome, dynamic Valor)
        {
            StdBECamposChave fields = new StdBECamposChave();

            fields.AddCampoChave(Nome, Valor);

            dynamic campo = fields.CamposChave;

            this.EntityKey = (string)campo[0].Valor;
        }

        ///

        /// This method is trigged by the ERP when the value of the bound category changes.
        ///
        void IStdBEInfRelacionada.Atualiza()
        {
            this.LoadGrid();
        }

        void IStdBEInfRelacionada.Limpa()
        {
            dataGridPendentes.DataSource = null;
        }

        #endregion
    }
}

6 - Set the application's 'Output path' to (C:Program Files (x86)PRIMAVERASG100Apl).

7 - Compile the solution in BUILD > Build Solution.

Bookmark or share this article
Esta página foi útil?
Obrigado pelo seu voto.
Related Articles
Getting Started How to create an integration project with Visual Studio? How to create an Interface Extensibility Project (PEX) with Visual Studio? How to create an API (Engine) extensibility project with Visual Studio? How to create user tabs with Visual Studio?