0
Good afternoon to all,
And thanks for your attention,
I created a C# code to transform documents.
I’m making a mistake:
Microsoft.CSharp.Runtimebinder.Runtimebinderexception
Hresult=0x80131500 Message='Object' does not contain a Definition for 'Davaloratributo' #Source= Stacktrace:
In VBA this code works perfectly, which I have done before successfully.
I marked the "-------------" line and commented on the line giving me the error.
...C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Interop.ErpBS900;
using Interop.StdPlatBS900;
using Interop.StdBE900;
using Interop.GcpBE900;
using Interop.IGcpBS900;
namespace Docs_Trans
{
class Program
{
public static StdPlatBS Platform { get; set; }
/// <summary>
/// Returns the engine that allows acess to the modules.
/// </summary>
public static ErpBS Engine { get; set; }
public static void InitializeCompany()
{
StdBSConfApl objAplConf = new StdBSConfApl();
StdPlatBS Plataforma = new StdPlatBS();
ErpBS MotorLE = new ErpBS();
EnumTipoPlataforma objTipoPlataforma = new EnumTipoPlataforma();
objTipoPlataforma = EnumTipoPlataforma.tpEmpresarial;
objAplConf.Instancia = "Default";
objAplConf.AbvtApl = "ERP";
objAplConf.PwdUtilizador = "pass";
objAplConf.Utilizador = "user";
objAplConf.LicVersaoMinima = "9.00";
StdBETransaccao objStdTransac = new StdBETransaccao();
Plataforma.AbrePlataformaEmpresa("empres", ref objStdTransac, ref objAplConf, ref objTipoPlataforma, "");
if (Plataforma.Inicializada)
{
Platform = Plataforma;
bool blnModoPrimario = true;
MotorLE.AbreEmpresaTrabalho(EnumTipoPlataforma.tpEmpresarial, "empresa", "user", "pass", ref objStdTransac, "Default", ref blnModoPrimario);
MotorLE.set_CacheActiva(true);
Engine = MotorLE;
////MOTORES DE CRIAR E TRANSFORMAR DOCUmento
///
////Query de pesquisa de documentos e colocação em lista para fazer o ciclo
StdBELista ListaDocsAtransformar = new StdBELista();
ListaDocsAtransformar = Engine.Consulta("select TipoDoc, Serie, NumDoc from CabecDoc where tipodoc in (select CDU_PNT_TIPODOCEQUIORIG from tdu_pnt_docsequivalencia) and serie in (select CDU_PNT_SERIEEQUIORIG from tdu_pnt_docsequivalencia) and CDU_PNT_TRANSFORMADO <> 1");
while (!ListaDocsAtransformar.NoFim())
{
GcpBEDocumentoVenda DocVendaTransformado = new GcpBEDocumentoVenda();
object DocumentosOrigem;
/// DocumentosOrigem = Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo( "000", "ECN", "serie", "numdoc", "ID"));
///----------
//// aqui tenho o erro a indicar que davaloratributo, não existe no object???
///----------
object IDDoc = Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID");
DocumentosOrigem = Engine.Comercial.Vendas.EditaID(IDDoc.ToString());
string[] DocumentosOrigemArray = (string[])DocumentosOrigem;
object DocInicial;
DocInicial = Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_TipoEntidade();
////Vai verificar qual o documento e serie correspondente
///
StdBELista ListaTipoDocSerie = new StdBELista();
ListaTipoDocSerie = Engine.Consulta("select CDU_PNT_TIPODOCEQUITRANS, CDU_PNT_SERIEEQUITRANS from tdu_pnt_DOCSEQUIVALENCIA where CDU_PNT_TIPODOCEQUIORIG = 'gr' and CDU_PNT_SERIEEQUIORIG = '2019'");
DocVendaTransformado.set_Serie(ListaTipoDocSerie.Valor("CDU_PNT_SERIEEQUITRANS").ToString());
DocVendaTransformado.set_DataDoc(DateTime.Today);
DocVendaTransformado.set_TipoEntidade(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_TipoEntidade());
DocVendaTransformado.set_TipoEntidadeFac(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_TipoEntidadeFac());
DocVendaTransformado.set_Entidade(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_Entidade());
DocVendaTransformado.set_EntidadeFac(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_EntidadeFac());
DocVendaTransformado.set_Filial(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_Filial());
DocVendaTransformado.set_Moeda(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_Moeda());
DocVendaTransformado.set_Cambio(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_Cambio());
DocVendaTransformado.set_CambioMAlt(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_CambioMAlt());
DocVendaTransformado.set_CambioMBase(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_CambioMBase());
DocVendaTransformado.set_Tipodoc(ListaTipoDocSerie.Valor("CDU_PNT_TIPODOCEQUITRANS").ToString());
DocVendaTransformado.set_CondPag(Engine.Comercial.Vendas.EditaID(Engine.Comercial.Vendas.DaValorAtributo("000", ListaDocsAtransformar.Valor("tipodoc").ToString(), ListaDocsAtransformar.Valor("serie").ToString(), Int32.Parse(ListaDocsAtransformar.Valor("numdoc").ToString()), "ID").ToString()).get_CondPag());
Engine.Comercial.Vendas.TransformaDocumentoEX2(DocumentosOrigemArray, DocVendaTransformado, true, "", false);
//cria historico
Platform.ExecSql.ExecutaXML("");
//update que foi transformado na CDU_PNT_TRANSFORMADO do cabecdoc
Platform.ExecSql.ExecutaXML("");
ListaDocsAtransformar.Seguinte();
}
}
}
static void Main(string[] args)
{
InitializeCompany();
}
}
}
...
Good morning, Solved the question of davalorAtribute is solved. Thanks This object to array conversion gives me the error of: "Unable to cast COM Object of type 'Interop.GCPBE900.Gcpbedocumentovendaclass' to class type System.String[]" "string[] Documentsorigemarray = (string[])((Object)Documentsorigem);" , which is also an issue I’m struggling with. If it is preferable I create another question.
– Miguel Neto
I edited the code and I put the correct one ( Object[] Documentosorigemarray = new Object[] { Documentosorigem }; ). Actually the array should be objects and not strings, as you were putting. If you solved the problem, mark the answer as valid ;)
– Manuel Quelhas