Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Company company = SAPHelper.GetCompany();

            if (company.Connected)
            {
                company.Disconnect();
            }
            int result = company.Connect();

            if (result != 0)
            {
                company.GetLastError(out ERROR_CODE, out ERROR_MESSAGE);
                Console.Error.Write($"({ERROR_CODE})-{ERROR_MESSAGE}");
                Console.Read();
                Environment.Exit(ERROR_CODE);
            }

            var udoManager = (UserObjectsMD)company.GetBusinessObject(BoObjectTypes.oUserObjectsMD);

            for (int i = 0; i < args.Length; i++)
            {
                var item = args[i];
                if (!udoManager.GetByKey(item))
                {
                    Console.WriteLine("Don't exists the UDO {0}", item);
                    continue;
                }
                Console.WriteLine("Removing UDO: {0} | Result: {1}", item, udoManager.Remove() == 0);
            }
            Console.WriteLine("Finish process");
            Console.Read();
            company.Disconnect();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes links between document and employees in SAP.
        /// NOT USED!
        /// </summary>
        /// <param name="env"></param>
        /// <param name="deletedIDs">List of employee IDs to be removed.</param>
        private void removeLinks(EventHandlerEnvironment env, IEnumerable <string> deletedIDs, SAPDataSource source)
        {
            foreach (string employeeID in deletedIDs)
            {
                string documentID = env.ObjVerEx.Properties.GetProperty(DocumentIDProperty).GetValueAsLocalizedText();
                string repository = env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty).GetValueAsUnlocalizedText();

                // Remove the link with RFC function
                IRfcFunction rfcFunction = SAPHelper.CreateFunction("ARCHIV_DELETE_META", source.getDestination());                    // Not usable outside SAP
                rfcFunction.SetValue("ARCHIV_ID", repository);
                rfcFunction.SetValue("SAP_OBJECT", "PREL");
                rfcFunction.SetValue("ARC_DOC_ID", documentID);
                rfcFunction.SetValue("OBJECT_ID", employeeID);
                try
                {
                    string result  = SAPHelper.InvokeRFC(rfcFunction, source.getDestination());
                    string message = "Removed link between document: " + documentID + "\n" +
                                     "and employee: " + employeeID + "\n" +
                                     result;
                    SysUtils.ReportInfoToEventLog(message);
                }
                catch (Exception ex)
                {
                    SysUtils.ReportErrorToEventLog("SAPDocumentConnector", ex.Message, ex);
                    throw new RfcInvalidParameterException(ex.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetDeliverySales()
        {
            _sap = new SAPHelper();
            var       now     = DateTime.Now.AddDays(-20);
            DataTable dsTable = _sap.DownloadDeliverySale("FI20", now, now.AddDays(1));

            if (dsTable != null && dsTable.Rows.Count > 0)
            {
                return(Ok(dsTable));
            }
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            Company company = SAPHelper.GetCompany();

            if (company.Connected)
            {
                company.Disconnect();
            }
            int result = company.Connect();

            if (result != 0)
            {
                company.GetLastError(out ERROR_CODE, out ERROR_MESSAGE);
                Console.Error.Write($"({ERROR_CODE})-{ERROR_MESSAGE}");
                Console.Read();
                Environment.Exit(ERROR_CODE);
            }

            var udoManager = (FormattedSearches)company.GetBusinessObject(BoObjectTypes.oFormattedSearches);
            var oRecordSet = (Recordset)company.GetBusinessObject(BoObjectTypes.BoRecordset);

            oRecordSet.DoQuery("select FRQ.IndexID, QRY.IntrnalKey, CAT.CategoryId from OQCN CAT, OUQR QRY, CSHS FRQ where CAT.CategoryId = QRY.QCategory and QRY.IntrnalKey = FRQ.QueryId and CAT.CatName like '%BPVS - Producción Agrícola%'");
            while (!oRecordSet.EoF)
            {
                int mappedIndexForm = int.Parse(oRecordSet.Fields.Item("IndexID").Value.ToString());
                if (!udoManager.GetByKey(mappedIndexForm))
                {
                    Console.WriteLine("Don't exists the match between UDO form and query");
                    continue;
                }
                Console.WriteLine("Removing match between UDO form and query: {0}", udoManager.Remove() == 0);
                oRecordSet.MoveNext();
            }
            oRecordSet.MoveFirst();
            var userQueries = (UserQueries)company.GetBusinessObject(BoObjectTypes.oUserQueries);

            while (!oRecordSet.EoF)
            {
                int queryId    = int.Parse(oRecordSet.Fields.Item("IntrnalKey").Value.ToString());
                int categoryId = int.Parse(oRecordSet.Fields.Item("CategoryId").Value.ToString());
                if (!userQueries.GetByKey(queryId, categoryId))
                {
                    Console.Error.WriteLine("Don't exists the query");
                    continue;
                }
                Console.WriteLine("Removing the query: {0}", userQueries.Remove() == 0);
                oRecordSet.MoveNext();
            }
            Console.WriteLine("Finish process, press any key");
            Console.Read();
            company.Disconnect();
        }
Ejemplo n.º 5
0
    private void 执行()
    {
        SAPHelper a = new SAPHelper();

        sRFCReturn = a.RunRFC(sRFC);
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates links between document and employees in SAP.
        /// </summary>
        /// <param name="env"></param>
        /// <param name="documentType"></param>
        /// <param name="newSAPObjects"></param>
        private void createLinks(StateEnvironment env, string documentType, string SAPObjectType, IEnumerable <string> newSAPObjects, SAPDataSource source)
        {
            foreach (string employeeID in newSAPObjects)
            {
                // Generate and set SAP properties
                string documentID = GUIDToDocumentID(env);
                env.ObjVerEx.Properties.SetProperty(DocumentIDProperty, MFDataType.MFDatatypeText, documentID);

                // Set properties required by SAP
                env.ObjVerEx.Properties.SetProperty(ComponentPropertiesProperty, MFDataType.MFDatatypeMultiLineText,
                                                    "ComponentID=data|ContentType=application/pdf|FileID=" + GetFileID(env) +
                                                    "|Filename=data.pdf|ADate=" + GetSAPDateFromTS(env.ObjVerEx.GetProperty(20).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|ATime=" + GetSAPTimeFromTS(env.ObjVerEx.GetProperty(20).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|MDate=" + GetSAPDateFromTS(env.ObjVerEx.GetProperty(21).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|MTime=" + GetSAPTimeFromTS(env.ObjVerEx.GetProperty(21).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|AppVer=|Charset=");
                env.ObjVerEx.SetProperty(DocumentProtectionProperty, MFDataType.MFDatatypeText, "rud");
                env.ObjVerEx.SetProperty(ArchiveLinkVersionProperty, MFDataType.MFDatatypeText, "0046");

                // Save properties
                env.ObjVerEx.SaveProperties();

                // Get SAP repository
                if (env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty) == null)
                {
                    throw new Exception("No SAP repository defined.");
                }
                string repository = env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty).GetValueAsUnlocalizedText();

                // Get filename
                string fileName = env.ObjVerEx.Title;

                // Get description
                string        description = "";
                PropertyValue descProp;
                if (env.ObjVerEx.Properties.TryGetProperty(DocumentDescriptionProperty, out descProp))
                {
                    description = descProp.GetValueAsLocalizedText();
                }

                // Do the link with RFC function
                IRfcFunction rfcFunction = SAPHelper.CreateFunction("ARCHIV_CONNECTION_INSERT", source.getDestination());
                rfcFunction.SetValue("ARCHIV_ID", repository);
                rfcFunction.SetValue("AR_OBJECT", documentType);
                rfcFunction.SetValue("SAP_OBJECT", SAPObjectType);
                rfcFunction.SetValue("ARC_DOC_ID", documentID);
                rfcFunction.SetValue("OBJECT_ID", employeeID);

                // Is the file info in use
                if (config.UseFileInfo == "true")
                {
                    rfcFunction.SetValue("FILENAME", fileName);
                    rfcFunction.SetValue("DESCR", description);
                    rfcFunction.SetValue("CREATOR", employeeID);
                }

                //
                try
                {
                    string result  = SAPHelper.InvokeRFC(rfcFunction, source.getDestination());
                    string message = "Linked document: " + documentID + ", type: " + documentType + "\n" +
                                     "with SAP object: " + employeeID + ", type: " + SAPObjectType + "\n" +
                                     "Filename: " + fileName + ", Description: " + description + "\n" +
                                     result;
                    SysUtils.ReportInfoToEventLog(message);
                }
                catch (Exception ex)
                {
                    // Show failed FRC call in Event viewer.
                    StringBuilder message = new StringBuilder()
                                            .AppendLine("ARCHIV_CONNECTION_INSERT")
                                            .AppendFormat(" - ARCHIV_ID: '{0}'", repository).AppendLine()
                                            .AppendFormat(" - AR_OBJECT: '{0}'", documentType).AppendLine()
                                            .AppendFormat(" - SAP_OBJECT: '{0}'", SAPObjectType).AppendLine()
                                            .AppendFormat(" - ARC_DOC_ID: '{0}'", documentID).AppendLine()
                                            .AppendFormat(" - OBJECT_ID: '{0}'", employeeID).AppendLine();
                    if (config.UseFileInfo == "true")
                    {
                        message
                        .AppendFormat(" - FILENAME: '{0}'", fileName).AppendLine()
                        .AppendFormat(" - DESCR: '{0}'", description).AppendLine()
                        .AppendFormat(" - CREATOR: '{0}'", employeeID).AppendLine();
                    }
                    message.AppendLine().AppendLine(ex.Message);
                    SysUtils.ReportErrorToEventLog("SAPDocumentConnector", message.ToString(), ex);

                    throw new RfcInvalidParameterException(ex.Message);
                }
            }
        }