Actually the simplest way, and for a very wide use of ERP , is to declare ErpBS
and evoke AbreEmpresaTrabalho
, but if we want a more robust specific and need access other resources that are not available in motor.DSO.Plat
(for example), we will have to implement something more complex / complete.
The most "clean" and optimal way to develop the solution we want is by creating a class that will implement a Singleton Pattern
(more info here: # ), which is basically a static class that will have everything we will need.
sealed class PriEngine: DisposableBase
{
#region Singleton pattern
// .NET guarantees thread safety for static initialization
private static readonly PriEngine engineInstance = new PriEngine();
/// <summary>
/// Private constructor
/// </summary>
private PriEngine()
{
}
public static PriEngine CreateContext(string Company, string User, string Password)
{
StdBSConfApl objAplConf = new StdBSConfApl();
StdPlatBS Plataforma = new StdPlatBS();
ErpBS MotorLE = new ErpBS();
EnumTipoPlataforma objTipoPlataforma;
objTipoPlataforma = EnumTipoPlataforma.tpEmpresarial;
objAplConf.Instancia = "Default";
objAplConf.AbvtApl = "ERP";
objAplConf.PwdUtilizador = Password;
objAplConf.Utilizador = User;
objAplConf.LicVersaoMinima = "10.00";
StdBETransaccao objStdTransac = new StdBETransaccao();
try
{
Plataforma.AbrePlataformaEmpresa(Company, objStdTransac, objAplConf, objTipoPlataforma);
}
catch (Exception ex)
{
throw (ex);
}
if (Plataforma.Inicializada)
{
MotorLE.AbreEmpresaTrabalho(objTipoPlataforma, Company, User, Password, objStdTransac, "Default");
Platform = Plataforma;
Engine = MotorLE;
EngineStatus = true;
}
return engineInstance;
}
#endregion
#region Public Properties
/// <summary>
/// The platform
/// </summary>
public static StdPlatBS Platform { get; private set; }
/// <summary>
/// The engine that allows access to the modules.
/// </summary>
public static ErpBS Engine { get; private set; }
/// <summary>
/// The engine status 0 - Fail | 1 - OK
/// </summary>
public static bool EngineStatus { get; private set; }
#endregion
#region IDisposable Members
protected override void Dispose(bool disposing)
{
// Check to see if Dispose has already been called
if (!this.Disposed)
{
}
// Dispose on base class
base.Dispose(disposing);
}
#endregion
}
Our motor
will become the PriEngine
object (single instance), accessible throughout the application.
To initialize the engine, you only need to call up the CreateContext
method only once:
PriEngine.CreateContext("MinhaEmpresa", "MeuUser", "MinhaPass");
In% w / w we will have access to two "large" objects, PriEngine
and Engine
, explained in more detail below.
Platform
= Engine
/ ErpBS
The object BSO
represents the engine itself, it is from here that we access all ERP modules.
In V10 the modules have been separated and the global engine Engine
ceases to exist, so the Sales , Purchases , Stocks and mainly Inventory can be directly evoked. Eg: Comercial
, PriEngine.Engine.Vendas
, PriEngine.Engine.Compras
, etc.
PriEngine.Engine.Base
= Platform
/ StdPlatBS
In vba we had access to the PSO
object where they were all available functions of the Platform . It was not necessary to boot because it was already available by default in the environment, but in specific, if we want to have access to the object, we have to initialize and load it correctly (namely evoking PSO
).
In class AbrePlataformaEmpresa
we do all this "work" and from the object PriEngine
(common Platform
) we have full access to Platform .