Пример #1
0
        public bool connectSAPserver(string _sapUserName, string _sapPassword, string _sapClient = null,
                                     string _sapLanguage = null, string _sapSystemNumber      = null, string _sapHost = null,
                                     string _sapSystemID = null, bool _replaceExistingInCache = false)
        {
            registerSAPServerDetails(_sapUserName, _sapPassword, _sapClient, _sapLanguage,
                                     _sapSystemNumber, _sapHost, _sapSystemID, _replaceExistingInCache);
            try
            {
                m_rfcDestination = RfcDestinationManager.GetDestination(DataCache.GetObject().SapDestinationName);

                //attempt actual function call
                IRfcFunction function = m_rfcDestination.Repository.CreateFunction("BAPI_COMPANYCODE_GETLIST");

                //RfcSessionManager.BeginContext(m_rfcDestination);

                //    function.Invoke(m_rfcDestination);

                //RfcSessionManager.EndContext(m_rfcDestination);

                //IRfcTable             returnTable        =  function.GetTable("COMPANYCODE_LIST");

                //for (int y = 0; y <= (returnTable.RowCount - 1); y += 1)
                //{
                //    for (int z = 0; z <= (returnTable[y].ElementCount - 1); z += 1)
                //    {
                //        string par = returnTable[y][z].Metadata.Name;
                //        string val = returnTable[y].GetString(z);

                //        string messageLine = par + " : " + val;
                //    }
                //}

                //foreach (var r in returnStructure.)
                //{
                //    foreach (var t in r)
                //    {
                //        //string par = returnTable[y][z].Metadata.Name;
                //        //string val = returnTable[y].GetString(z);

                //        //string messageLine = par + " : " + val;
                //        //writer.WriteLine(messageLine);

                //        string a = r.Metadata.Name;
                //        string b = r.GetString(a);
                //    }
                //    //writer.WriteLine(" ");
                //}

                OnLogonComplete?.Invoke();

                return(true);
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return(false);
        }
Пример #2
0
 public void ResetSAPConnection()
 {
     try
     {
         this.m_rfcDestination = null;
     }
     catch (Exception e)
     {
     }
 }
Пример #3
0
        public bool connectSAPserver()
        {
            m_rfcDestination = null;
            try
            {
                m_rfcDestination = RfcDestinationManager.GetDestination(DataCache.GetObject().SapDestinationName);

                OnLogonComplete?.Invoke();

                return(true);
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return(false);
        }
Пример #4
0
 public static void BeginContext(RfcDestination destination)
 {
 }
Пример #5
0
        private void registerSAPServerDetails(string _sapUserName, string _sapPassword, string _sapClient = null,
                                              string _sapLanguage = null, string _sapSystemNumber      = null, string _sapHost = null,
                                              string _sapSystemID = null, bool _replaceExistingInCache = false)
        {
            m_rfcDestination = null;
            DataCache.GetObject().ClearCache();

            try
            {
                if (String.IsNullOrEmpty(DataCache.GetObject().SapClient) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapClient = (!String.IsNullOrEmpty(_sapClient))   ?   _sapClient : string.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapClient))
                {
                    throw new Exception("Please provide valid client number");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapLanguage) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapLanguage = (!String.IsNullOrEmpty(_sapLanguage))  ?   _sapLanguage : String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapLanguage))
                {
                    throw new Exception("Please provide valid SAP Language");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapSystemNumber) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapSystemNumber = (!String.IsNullOrEmpty(_sapSystemNumber))  ?  _sapSystemNumber :  String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapSystemNumber))
                {
                    throw new Exception("Please provide valid SAP System Number");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapHost) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapHost = (!String.IsNullOrEmpty(_sapHost))     ?       _sapHost       :  String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapHost))
                {
                    throw new Exception("Please provide valid SAP Host");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapSystemID) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapSystemID = (!String.IsNullOrEmpty(_sapSystemID)) ?     _sapSystemID   :  String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapSystemID))
                {
                    throw new Exception("Please provide valid SAP ID");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapUserName) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapUserName = (!String.IsNullOrEmpty(_sapUserName))  ?   _sapUserName  : String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapUserName))
                {
                    throw new Exception("Please provide valid SAP User Name");
                }

                if (String.IsNullOrEmpty(DataCache.GetObject().SapLogonPassword) || _replaceExistingInCache)
                {
                    DataCache.GetObject().SapLogonPassword = (!String.IsNullOrEmpty(_sapPassword))  ? _sapPassword  :  String.Empty;
                }
                else if (String.IsNullOrEmpty(DataCache.GetObject().SapLogonPassword))
                {
                    throw new Exception("Please provide valid SAP User Password");
                }

                if (m_rfcDestination == null)
                {
                    m_provider = new MatManLib.SapLogonConfig();

                    if (RfcDestinationManager.TryGetDestination(DataCache.GetObject().SapDestinationName) == null)
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(m_provider);
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }