Print sales document through the engines for a specific printer (V9.15)

2

Using the C # integration engines, I need to print a sales document automatically after creating it, using a specific printer, without any user interaction. The code I have is the following:

Interop.GcpBE900.GcpBEDocumentoVenda doc = new Interop.GcpBE900.GcpBEDocumentoVenda();

//preencher propriedades, linhas, etc...
//Criar documento...

//Após gravação com sucesso e etc, fazer a impressão do mesmo
BSO.Comercial.Vendas.ImprimeDocumento(doc.get_Tipodoc(), doc.get_Serie(), doc.get_NumDoc(), doc.get_Filial());

I've excluded validations, try blocks, and so on. to simplify the question. This code works fine, but goes to the default printer. I needed to be able to specify which target printer, and it will exist on the same network, obviously.

Is it possible? Is there any property or method to this effect?

Thank you in advance.

UPDATE: Using the suggestion of Nuno Peixoto, (whom I thank immensely for the answer); and completing the code with the existing in this answer , although no error is obtained, printing is not done. The complete code I'm using is the following:

public static void ImprimirDocVenda(Interop.ErpBS900.ErpBS BSO, 
Interop.StdPlatBS900.StdPlatBS PSO, Interop.GcpBE900.GcpBEDocumentoVenda doc)
        {
            try
            {
            var reportTemplate = BSO.Consulta($"SELECT Config FROM SeriesVendas WHERE TipoDoc = '{doc.get_Tipodoc()}' AND Serie = '{doc.get_Serie()}'").Valor("Config");
            var numVias = BSO.Consulta($"SELECT ISNULL(NumVias,0) AS NumVias FROM SeriesVendas WHERE TipoDoc = '{doc.get_Tipodoc()}' AND Serie = '{doc.get_Serie()}'").Valor("NumVias");
            var strSelFormula = $"{{CabecDoc.TipoDoc}}=\'{doc.get_Tipodoc()}\' and {{CabecDoc.Serie}} = \'{doc.get_Serie()}\' AND {{CabecDoc.NumDoc}}={Convert.ToString(doc.get_NumDoc())}";

            PSO.Mapas.Inicializar("GCP");
            PSO.Contexto.Erp.set_Inicializado(true);
            PSO.Mapas.AddFormula("NomeLicenca", $"'{BSO.Licenca.get_Nome()}'");
            PSO.Mapas.set_VerificarBdAntesImpressao(false);

            var strFormula = new System.Text.StringBuilder();
            strFormula.Append($"StringVar Nome:='{BSO.Contexto.IDNome}';");
            strFormula.Append($"StringVar Morada:='{BSO.Contexto.IDMorada}';");
            strFormula.Append($"StringVar Localidade:='{BSO.Contexto.IDLocalidade}';");
            strFormula.Append($"StringVar CodPostal:='{BSO.Contexto.IDCodPostal} {BSO.Contexto.IDCodPostalLocal}';");
            strFormula.Append($"StringVar Telefone:='{BSO.Contexto.IDTelefone}';");
            strFormula.Append($"StringVar Fax:='{BSO.Contexto.IDFax}';");
            strFormula.Append($"StringVar Contribuinte:='{BSO.Contexto.IFNIF}';");
            strFormula.Append($"StringVar CapitalSocial:='{BSO.Contexto.ICCapitalSocial}';");
            strFormula.Append($"StringVar Conservatoria:='{BSO.Contexto.ICConservatoria}';");
            strFormula.Append($"StringVar Matricula:='{BSO.Contexto.ICMatricula}';");
            strFormula.Append($"StringVar MoedaCapitalSocial:='{BSO.Contexto.ICMoedaCapSocial}';");

            PSO.Mapas.SetFormula("DadosEmpresa", strFormula.ToString());

            var strParametros = new System.Text.StringBuilder();
            strParametros.Append("NumberVar TipoDesc;");
            strParametros.Append("NumberVar DecQde;");
            strParametros.Append("NumberVar DecPrecUnit;");
            strParametros.Append("StringVar MotivoIsencao;");
            strParametros.Append("BooleanVar UltimaPag;");
            strParametros.Append("TipoDesc:= 0;");
            strParametros.Append("DecQde:=3;");
            strParametros.Append($"DecPrecUnit:={PSO.FuncoesGlobais.DaCasasDecimais("Moedas", "DecArredonda")};");
            strParametros.Append("UltimaPag:=False;");

            PSO.Mapas.SetFormula("InicializaParametros", strParametros.ToString());
            PSO.Mapas.set_Destino(Interop.StdPlatBS900.CRPEExportDestino.edFicheiro);

            string file = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";
            PSO.Mapas.SetFileProp(Interop.StdPlatBS900.CRPEExportFormat.efPdf, file);

            PSO.Mapas
                .DefinicaoImpressoraIntegracao(
                "EPSON05EC84 (WF-5620 Series)"
                , "winspool"
                , "EPSON05EC84 (WF-5620 Series)"
                , "Ne06:"
                , Interop.StdPlatBS900.CRPEOrientacaoFolha.ofPortrait
                , 360
                , Interop.StdPlatBS900.CRPETipoFolha.tfA4
                , 11904
                , 16836
                , Convert.ToInt16(numVias)
                , 1
                , 1
                , 1
                , 1
                );

            PSO.Mapas
                .ImprimeListagem(
                reportTemplate.ToString()
                , "Venda"
                , "P"
                , Convert.ToInt16(numVias)
                , "N"
                , strSelFormula
                , Interop.StdPlatBS900.CRPESentidoOrdenacao.soDescendente
                , false
                , true
                );

         }
        catch (Exception)
        {
            throw;
        }
    }

The parameters of the printer in question, removed them from the user's In settings after saving the printer configuration in the preferences in the ERP Spring.

I will certainly be doing something less well. If I could identify the problem, I was very grateful.

    
asked by anonymous 12.10.2018 / 19:39

1 answer

5

Good evening, if you use the ImprimeListagem of class Mapas of Platform , you can set the printer by using the DefinicaoImpressoraEx or DefinicaoImpressoraIntegracao methods.

Note that all parameters in this method should map correctly to those of the printer concerned.

Here's an example of a fairly common PDF printer (CutePDF):

plat_.Mapas.DefinicaoImpressoraIntegracao("CutePDF Writer", "CutePDF Writer", "CutePDF Writer", "CPW2:", 1, 600, 9, 27, 21, 1, 0, 1, 1, 1);
...
plat_.Mapas.ImprimeListagem(report, "Factura", "P", 1, "N", formula, 0, false, true)

I leave the whole configuration of the document to be printed in this response.

    
12.10.2018 / 22:11