Skip to Content

Hello Friends,

I leave this post about the connection method on a .NET c# project SAP Business One AddOn, of a report build in Crystal Report 13 and 11 who will be use in SAP Business One version for HANA, hope this will work for you like was for me.

best Regards

SAMPLE CODE:

        public static bool buildCrystalReportAlmacen(int strDocEntry,string oAlmacen,string oPrinterName, string oUserId)

        {

            bool Retorno = false;

            string strDSN = “”;

            string strAccount = “”;

            string strDbName = “”;

            try

            {

                ReportDocument Zona_Despacho_V1 = new ReportDocument(); // se instancia el reporte

                Zona_Despacho_V1.Load(Environment.CurrentDirectory + @”\Zona_Despacho_V1.rpt”); //ruta donde se toma el archivo .rpt

                Zona_Despacho_V1.SetParameterValue(“DocEntry”, strDocEntry); // pasa los parametros

                Zona_Despacho_V1.SetParameterValue(“Almacen”, oAlmacen);

                strDSN = SBO_Eventos.Globals.strDSN; //server HANA

                strAccount = SBO_Eventos.Globals.strAccount; //usuario

                strDbName = SBO_Eventos.Globals.strDbName; //nombre de la base de datos

                #region OBTENCION DEL PASWORD Y EL NUMERO DE COPIAS DEL REPORTE

                SAPbobsCOM.Recordset oRs = (SAPbobsCOM.Recordset)SBO_Conexion.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

                oRs.DoQuery(Consultas.ConsultaPwsNroCopias());

                oPws = oRs.Fields.Item(“U_NX_PWSCR”).Value.ToString(); //PASWORD PARA ESTA VERSION

                oNroCopias = Convert.ToInt32(oRs.Fields.Item(“U_NX_NRPRINT”).Value.ToString()); // NUMERO DE COPIAS PAR AESTA VERSION

                #endregion OBTENCION DEL PASWORD Y EL NUMERO DE COPIAS DE IMPRESION DEL REPORTE

                string strConnection = “DRIVER= {B1CRHPROXY32};UID=” + strAccount; //string de conexion contruido de las variables

                strConnection += “;PWD=” + oPws + “;SERVERNODE=” + strDSN;

                strConnection += “;DATABASE=” + strDbName + “;”;

                NameValuePairs2 logonProps2 = Zona_Despacho_V1.DataSourceConnections[0].LogonProperties;

                logonProps2.Set(“Provider”, “B1CRHPROXY32”);

                logonProps2.Set(“Server Type”, “B1CRHPROXY32”);

                logonProps2.Set(“Connection String”, strConnection);

                logonProps2.Set(“Locale Identifier”, “1033”);

                Zona_Despacho_V1.DataSourceConnections[0].SetLogonProperties(logonProps2);

                Zona_Despacho_V1.DataSourceConnections[0].SetConnection(strDSN, strDbName, strAccount, oPws);

                Zona_Despacho_V1.PrintOptions.PrinterName = oPrinterName; //nombre de la impresora a utilizar

                Zona_Despacho_V1.PrintToPrinter(oNroCopias, false, 1, oNroCopias); //se genera y se imprime el reporte

                Zona_Despacho_V1.Close(); //se cierra el reporte  

                Zona_Despacho_V1.Dispose(); // se libera el reporte

                Program.SBO_Application.StatusBar.SetText(“Se ha generado la impresion de picking por Zona de despacho”, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);

                Retorno = true;

            }

            catch (Exception er)

            {

                Program.SBO_Application.StatusBar.SetText(AddOn_NXIDP.Properties.Resources.AddOn_Name + ” Error: CrystalReports.cs > buildCrystalReportAlmacen():  “

                     + er.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);

                #region MENSAJE A USUARIO BODEGA POR FALLA DE IMPRESION

                EnviarMensajeBodega(oUserId, oAlmacen, null, er.Message,SBO_Eventos.Globals.oPedido.DocNum.ToString());

                #endregion MENSAJE A USUARIO BODEGA POR FALLA DE IMPRESION

                Retorno = false;

               

            }

            return Retorno;

        }

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply