Пример #1
0
 public void TestConnect()
 {
     if (destination != null)
     {
         destination.Ping();
     }
 }
Пример #2
0
        public static DataTable Query(SapParameters sap)
        {
            DataTable dt = new DataTable();

            try
            {
                RfcDestination rfc = sap.ServerHost;

                rfc.Ping();

                RfcRepository repo     = rfc.Repository;
                IRfcFunction  function = repo.CreateFunction(sap.FunctionName);

                foreach (KeyValuePair <string, string> keyValuePair in sap.Parameter)
                {
                    function.SetValue(keyValuePair.Key, keyValuePair.Value);
                }

                function.Invoke(rfc);

                IRfcTable rfcTable = function.GetTable(sap.TableName);
                dt = GetDataTableFromRFCTable(rfcTable);

                _isConnec = true;
            }
            catch (System.Exception ex)
            {
                _isConnec = false;
                logeer.InfoFormat("{0}", ex.Message);
            }

            return(dt);
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                SAPSystemConnect sapCfg = new SAPSystemConnect();
                RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
                RfcDestination destination = RfcDestinationManager.GetDestination("ECQ");
                RfcRepository  repository  = destination.Repository;
                IRfcFunction   function    = repository.CreateFunction("Z_SSRT_SUM");
                function.SetValue("i_num1", 2);
                function.SetValue("i_num2", 4);
                function.Invoke(destination);
                int result = function.GetInt("e_result");

                destination.Ping();
                var rfcRepository = destination.Repository;
                var rfcFunction   = rfcRepository.CreateFunction("RFC_CUSTOMER_DATA");
                rfcFunction.SetValue("COUNTRY", "india");
                rfcFunction.Invoke(destination);
                var table = rfcFunction.GetTable(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }
Пример #4
0
        public bool conectar()
        {
            RfcConfigParameters oParametros = new RfcConfigParameters();

            oParametros.Add(RfcConfigParameters.Name, sapName);
            oParametros.Add(RfcConfigParameters.User, sapUser);
            oParametros.Add(RfcConfigParameters.Password, sapPass);
            oParametros.Add(RfcConfigParameters.Client, sapClient);
            //oParametros.Add(RfcConfigParameters.Language, "EN");
            oParametros.Add(RfcConfigParameters.Language, "ES");
            oParametros.Add(RfcConfigParameters.AppServerHost, sapServer);
            oParametros.Add(RfcConfigParameters.SystemNumber, sapNumber);
            if (!sapRouter.Equals("") && !sapRouter.Equals(null))
            {
                oParametros.Add(RfcConfigParameters.SAPRouter, sapRouter);
            }
            if (!sapID.Equals("") && !sapID.Equals(null))
            {
                oParametros.Add(RfcConfigParameters.SystemID, sapID);
            }
            oParametros.Add(RfcConfigParameters.PoolSize, "5");

            oDestino = RfcDestinationManager.GetDestination(oParametros);

            try
            {
                oDestino.Ping();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
            return(true);
        }
Пример #5
0
        public bool Login(ProxyParameter parameter)
        {
            try
            {
                RfcConfigParameters confParam = new RfcConfigParameters();
                confParam.Add(RfcConfigParameters.Name, Guid.NewGuid().ToString());
                confParam.Add(RfcConfigParameters.AppServerHost, parameter.AppServerHost);
                confParam.Add(RfcConfigParameters.SAPRouter, parameter.SAPRouter);
                confParam.Add(RfcConfigParameters.Client, parameter.Client);
                confParam.Add(RfcConfigParameters.User, parameter.User);
                confParam.Add(RfcConfigParameters.Password, parameter.Password);
                confParam.Add(RfcConfigParameters.SystemNumber, parameter.SystemNumber);
                confParam.Add(RfcConfigParameters.Language, parameter.Language);
                confParam.Add(RfcConfigParameters.PoolSize, "1");
                confParam.Add(RfcConfigParameters.MaxPoolSize, "10");
                confParam.Add(RfcConfigParameters.IdleTimeout, "10");

                destination = RfcDestinationManager.GetDestination(confParam);
                destination.Ping();

                connected = true;
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message + " " + ex.StackTrace);
                System.Diagnostics.Trace.WriteLine(ex.Message + " " + ex.StackTrace);
            }
            return(connected);
        }
Пример #6
0
 public bool Ping(RfcDestination connectDestination)
 {
     try
     {
         connectDestination.Ping();
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("No ha sido posible realizar la conexión con SAP. Causa: {0}", ex));
     }
 }
Пример #7
0
 public bool Ping()
 {
     try
     {
         _destino.Ping();
         return(true);
     }
     catch (Exception)
     {
         // Si el ping falla es porque no hubo conexión con el destino
         return(false);
     }
 }
Пример #8
0
        public bool TestConnection()
        {
            bool result = false;


            SAPDestinationConfiguration sapDestinationConfiguration = new SAPDestinationConfiguration();


            try
            {
                // ishak.kulekci 24.06.2013
                //  Destination configuration already initialized hatasını engelleme, bunun için önce TryGetDestination kullanılır
                RfcDestination rfcDestination = RfcDestinationManager.TryGetDestination("SAPSYSTEM");
                if (rfcDestination == null)
                {
                    try
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(sapDestinationConfiguration);
                    }
                    catch (Exception ex)
                    {
                    }
                    rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM");
                }

                if (rfcDestination != null)
                {
                    rfcDestination.Ping();
                    result = true;
                }
            }
            catch (Exception exception)
            {
                //throw exception;
                result = false;
                //throw new Exception("Connection failure error. Message:"+exception.Message);
            }
            finally
            {
                try
                {
                    RfcDestinationManager.UnregisterDestinationConfiguration(sapDestinationConfiguration);
                }
                catch (Exception ex)
                {
                }
            }

            return(result);
        }
 //prueba la conexion con SAP
 public void Conexion()
 {
     try
     {
         if (rfcDestination != null)
         {
             rfcDestination.Ping();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Error Conexion() --> " + ex.Message + " -->");
     }
 }
Пример #10
0
 //prueba la conexion con SAP
 public void Conexion()
 {
     try
     {
         if (rfcDestination != null)
         {
             rfcDestination.Ping();
             //System.Diagnostics.Debug.WriteLine("God Job Try!!");
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Connection Failure Error --> " + ex.Message);
     }
 }
Пример #11
0
        public static string CheckSAPConnection()
        {
            Innovator innovator = IomFactory.CreateInnovator(connection);
            string    result;

            Item queryPart = innovator.newItem("GAG_SAPInterfaceSettings", "get");

            queryPart.setProperty("gag_active", "Yes");
            Item queryResult = queryPart.apply();

            if (queryResult.isEmpty())
            {
                result = "No SAP Connection Found. Contact Admin";
                return(result);
            }
            try
            {
                Item sapResult = queryResult.getItemByIndex(0);
                RfcConfigParameters parameters = new RfcConfigParameters
                {
                    [RfcConfigParameters.Name]                  = sapResult.getProperty("gag_name"),
                    [RfcConfigParameters.User]                  = ConfigurationManager.AppSettings.Get("userSAP"),
                    [RfcConfigParameters.Password]              = ConfigurationManager.AppSettings.Get("passwordSAP"),
                    [RfcConfigParameters.PeakConnectionsLimit]  = sapResult.getProperty("gag_peak_connection_limit"),
                    [RfcConfigParameters.ConnectionIdleTimeout] = sapResult.getProperty("gag_connection_idle_time_out"),
                    [RfcConfigParameters.Language]              = sapResult.getProperty("gag_language"),
                    [RfcConfigParameters.AppServerHost]         = sapResult.getProperty("gag_app_server_host"),
                    [RfcConfigParameters.SystemNumber]          = sapResult.getProperty("gag_system_number"),
                    [RfcConfigParameters.Client]                = sapResult.getProperty("gag_client")
                };
                destination = RfcDestinationManager.GetDestination(parameters);
                RfcSessionManager.BeginContext(destination);
                destination.Ping();

                result = "Connection Successful";
                return(result);
            }
            catch (RfcLogonException)
            {
                result = "SAP Log-In Failed";
                return(result);
            }
            catch (RfcCommunicationException)
            {
                result = "SAP Server Connection Error";
                return(result);
            }
        }
Пример #12
0
        public static void Init(ConnectionInformations ci)
        {
            RfcDestination dest = null;

            try
            {
                dest = RfcDestinationManager.GetDestination(ci.Name);
            }
            catch { }
            if (dest == null)
            {
                connectionInfo.AddOrEditDestination(ci);
                dest = RfcDestinationManager.GetDestination(ci.Name);
            }
            dest.Ping();
        }
Пример #13
0
        //增加一个连接配置,如果可以登录成功,加到内存中。
        private void addConfig()
        {
            try
            {
                if (!check())
                {
                    return;
                }
                _config               = new SapConfigClass();
                _config.Name          = cbxName.Text.Trim().ToUpper();
                _config.AppServerHost = txtAppServerHost.Text.Trim().ToUpper();
                _config.SAPRouter     = txtRouter.Text.Trim().ToUpper();
                _config.SystemID      = txtSystemId.Text.Trim().ToUpper();
                _config.SystemNumber  = txtSystemNumber.Text.Trim().ToUpper();
                _config.User          = txtUser.Text.Trim().ToUpper();
                _config.Password      = txtPassword.Text.Trim();
                _config.Client        = txtClient.Text.Trim().ToUpper();
                _config.Language      = txtLanguage.Text.Trim().ToUpper();
                // _config.PoolSize = "5";
                // _config.MaxPoolSize = "10";
                // _config.IdleTimeout = "60";

                RfcDestination des = SAPDestination.GetDesByConfig(_config);
                des.Ping();
                SAPLogonConfigList.AddConfig(_config.Name, _config);
            }
            catch (RfcLogonException e)
            {
                var s = e.Message;
                if ("LOGON_FAILURE" == e.Key)
                {
                    s = s + "登陆失败";
                }
                throw new SAPException(e.Key + s);
            }
            catch (RfcAbapRuntimeException e)
            {
                throw new SAPException(e.Key + e.Message);
            }
            catch (RfcAbapException e)
            {
                throw new SAPException(e.Key + e.Message);
            }
        }
Пример #14
0
        /// <summary>
        /// test ok
        /// </summary>
        /// <param name="destinationName"></param>
        /// <returns></returns>
        public bool TestConnection(string destinationName)
        {
            bool result = false;

            try
            {
                rfcDestination = RfcDestinationManager.GetDestination(destinationName);
                if (rfcDestination != null)
                {
                    rfcDestination.Ping();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
Пример #15
0
        public bool testconnection(string destinationname)
        {
            bool result = false;

            try
            {
                RfcDestination = RfcDestinationManager.GetDestination(destinationname);
                if (RfcDestination != null)
                {
                    RfcDestination.Ping();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                result = false;
                throw new Exception("Error de conexión " + ex.Message);
            }
            return(result);
        }
Пример #16
0
        public bool TestConnection(RfcDestination destination)
        {
            bool result = false;

            try
            {
                if (destination != null)
                {
                    destination.Ping();
                    result = true;
                }
            }
            catch (Exception e)
            {
                result = false;
                throw new Exception("Connection Failure: " + e.Message);
            }

            return(result);
        }
Пример #17
0
        public bool TestConnection(string destinationName)
        {
            bool result = false;

            try
            {
                rfcDestination = RfcDestinationManager.GetDestination(destinationName);
                if (rfcDestination != null)
                {
                    rfcDestination.Ping();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Connection Failure Error :" + ex.Message);
            }

            return(result);
        }
Пример #18
0
        public string connectionsSAP(string user, string pass)
        {
            string mensaje = null;

            connectorConfig = SAPConector(user, pass);
            try
            {
                RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(connectorConfig);
                SapRfcDestination.Ping();
            }
            catch (RfcLogonException ex)
            {
                mensaje = ex.Message;
            }
            catch (RfcCommunicationException exp)
            {
                mensaje = exp.Message;
            }
            finally { }

            return(mensaje);
        }
Пример #19
0
        private void Save_Database(string fingerprint)
        {
            RfcConfigParameters parameters = new RfcConfigParameters();

            parameters[RfcConfigParameters.Name]          = SAPFingerprint.Properties.Settings.Default.Name;
            parameters[RfcConfigParameters.User]          = txtUser.Text;
            parameters[RfcConfigParameters.Password]      = txtPass.Text;
            parameters[RfcConfigParameters.Client]        = SAPFingerprint.Properties.Settings.Default.Client;
            parameters[RfcConfigParameters.Language]      = SAPFingerprint.Properties.Settings.Default.Language;
            parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost;
            parameters[RfcConfigParameters.SystemNumber]  = SAPFingerprint.Properties.Settings.Default.SystemNumber;
            parameters[RfcConfigParameters.SAPRouter]     = SAPFingerprint.Properties.Settings.Default.SAPRouter;
            parameters[RfcConfigParameters.SystemID]      = SAPFingerprint.Properties.Settings.Default.SystemID;

            RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters);

            RfcSessionManager.BeginContext(SapRfcDestination);

            SapRfcDestination.Ping();
            IRfcFunction function = null;

            try
            {
                function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                function.SetValue("IM_FINGERPRINT", fingerprint);
                function.SetValue("IM_MODE", "R");
                function.SetValue("IM_UNAME", txtUser.Text);


                function.Invoke(SapRfcDestination);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }

            RfcSessionManager.EndContext(SapRfcDestination);
            SapRfcDestination = null;
        }
Пример #20
0
        private bool Connect()
        {
            bool result = false;

            try
            {
                oRFC = RfcDestinationManager.GetDestination(oConfigParameters);
                if (oRFC != null)
                {
                    oRFC.Ping();
                    result = true;
                }
                else
                {
                    throw new Exception("Error trying to connect. RFCDestination Null");
                }
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }
            return(result);
        }
Пример #21
0
        public void ZFI_GL_PROCESSING()
        {
            RfcDestination rfcDestination = GetParameters();

            rfcDestination.Ping();
        }
Пример #22
0
        public void ZFI_AP_DOC_POSTING()
        {
            RfcDestination rfcDestination = GetParameters();

            rfcDestination.Ping();
        }
Пример #23
0
        /// <summary>
        /// 测试SAP连接
        /// </summary>
        public void PingDestination()
        {
            RfcDestination destination = this.GetDestination();

            destination.Ping();
        }
Пример #24
0
        public void get_integracao()
        {
            List <Classes.ParametroRFC> parametros = new List <Classes.ParametroRFC> {
                new Classes.ParametroRFC()
                {
                    TIPO_REGISTRO = "1"
                },
                new Classes.ParametroRFC()
                {
                    TIPO_REGISTRO = "2"
                },
                new Classes.ParametroRFC()
                {
                    TIPO_REGISTRO = "3"
                }
            };

            // Cria parametros de conexão
            RfcConfigParameters meusap = new RfcConfigParameters();

            // Alimenta parametros SAP Logon
            meusap.Add(RfcConfigParameters.Name, txt_name.Text);
            meusap.Add(RfcConfigParameters.AppServerHost, txt_host.Text);
            meusap.Add(RfcConfigParameters.SystemNumber, txt_number.Text);

            // Alimenta parametros SAP GUI
            meusap.Add(RfcConfigParameters.Client, txt_client.Text);
            meusap.Add(RfcConfigParameters.User, txt_user.Text);
            meusap.Add(RfcConfigParameters.Password, txt_pass.Text);
            meusap.Add(RfcConfigParameters.SAPRouter, txt_sao_router.Text);

            // Cria destino
            RfcDestination meurfc = RfcDestinationManager.GetDestination(meusap);

            try
            {
                if (meurfc != null)
                {
                    // Verifica conexão
                    meurfc.Ping();
                    lbl_status.Text = "SAP - Conectado com sucesso.";

                    // Lê tabela
                    RfcRepository repo = meurfc.Repository;

                    // Define função de exportação de textos
                    IRfcFunction funcaoRT = repo.CreateFunction("ZSD_RFC_INTEGRACAO");

                    // Define parametros da função
                    IRfcTable tab_parametro = funcaoRT.GetTable("T_PARAMETER");

                    IRfcStructure p_estrutura = funcaoRT.GetStructure("P_ESTRUTURA");

                    foreach (Classes.ParametroRFC item in parametros)
                    {
                        tab_parametro.Insert();

                        tab_parametro[tab_parametro.CurrentIndex].SetValue("TIPO_REGISTRO", item.TIPO_REGISTRO.ToString());

                        p_estrutura.SetValue("TIPO_REGISTRO", item.TIPO_REGISTRO.ToString());
                    }

                    //funcaoRT.SetValue("TABELA", parametros);

                    // Chama função
                    funcaoRT.Invoke(meurfc);

                    // Recupera Dados cru, você precisa trata-los para
                    // que sejam humanamente legivelif
                    IRfcStructure tabela = funcaoRT.GetStructure("P_RETURN");

                    // Recupera texto
                    string dados = tabela.GetValue(3).ToString();

                    // Workaround para limpar tabela
                    // Existem métodos mais eficientes
                    // Este é apenas um caminho rápido para exemplo
                    // Também há possibilidades em diferentes funções e BAPis
                    // Converter um set de dados da função em um set de dados .NET
                    dados = dados.Replace("TABLE  [STRUCTURE TAB512 { FIELD WA=", "");
                    dados = dados.Replace("[STRUCTURE TAB512 { FIELD WA=", "");
                    dados = dados.Replace("}]", "\n");

                    // alimenta GUI
                    txt_return.AppendText(dados.TrimStart());
                }
            }
            catch (Exception ex)
            {
                // Erro ao conectar
                lbl_status.Text = "SAP - Problema de Conexão";
                MessageBox.Show(ex.Message.ToString(), "Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #25
0
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case MESSAGE_CAPTURED_OK:
            {
                MemoryStream ms = new MemoryStream();
                BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                Bitmap bmp = new Bitmap(ms);
                this.picFPImg.Image = bmp;

                String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp);


                if (IsRegister)
                {
                    int ret = zkfp.ZKFP_ERR_OK;
                    int fid = 0, score = 0;
                    ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score);
                    if (zkfp.ZKFP_ERR_OK == ret)
                    {
                        txtStatus.Text = "This finger was already register";
                        return;
                    }

                    if (RegisterCount > 0 && zkfp2.DBMatch(mDBHandle, CapTmp, RegTmps[RegisterCount - 1]) <= 0)
                    {
                        txtStatus.Text = "Please press the same finger 1 times for the enrollment.";
                        return;
                    }

                    Array.Copy(CapTmp, RegTmps[RegisterCount], cbCapTmp);
                    String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp);


                    byte[] blob = zkfp2.Base64ToBlob(strBase64);
                    RegisterCount++;

                    Save_Database(strBase64);

                    if (RegisterCount >= REGISTER_FINGER_COUNT)
                    {
                        txtStatus.Text = "Enroll succesfully";

                        IsRegister = false;
                        cbRegTmp   = 1;
                        return;
                    }
                    else
                    {
                        txtStatus.Text = "You need to press the " + (REGISTER_FINGER_COUNT - RegisterCount) + " times fingerprint";
                    }
                }
                else
                {
                    if (cbRegTmp <= 0)
                    {
                        txtStatus.Text = "Please register your finger first!";
                        return;
                    }
                    if (bIdentify)
                    {
                        int ret = zkfp.ZKFP_ERR_OK;
                        int fid = 0, score = 0;
                        ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score);
                        if (zkfp.ZKFP_ERR_OK == ret)
                        {
                            txtStatus.Text = "Identify succesfully, fid= " + fid + ",score=" + score + "!";
                            return;
                        }
                        else
                        {
                            txtStatus.Text = "Identify failed, ret= " + ret;
                            return;
                        }
                    }
                    else
                    {
                        RfcConfigParameters parameters = new RfcConfigParameters();

                        parameters[RfcConfigParameters.Name]          = SAPFingerprint.Properties.Settings.Default.Name;
                        parameters[RfcConfigParameters.User]          = txtUser.Text;
                        parameters[RfcConfigParameters.Password]      = txtPass.Text;
                        parameters[RfcConfigParameters.Client]        = SAPFingerprint.Properties.Settings.Default.Client;
                        parameters[RfcConfigParameters.Language]      = SAPFingerprint.Properties.Settings.Default.Language;
                        parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost;
                        parameters[RfcConfigParameters.SystemNumber]  = SAPFingerprint.Properties.Settings.Default.SystemNumber;
                        parameters[RfcConfigParameters.SAPRouter]     = SAPFingerprint.Properties.Settings.Default.SAPRouter;
                        parameters[RfcConfigParameters.SystemID]      = SAPFingerprint.Properties.Settings.Default.SystemID;

                        RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters);
                        RfcSessionManager.BeginContext(SapRfcDestination);

                        SapRfcDestination.Ping();
                        IRfcFunction function = null;

                        try
                        {
                            function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                            function.SetValue("IM_MODE", "V");

                            IRfcTable gt_table = function.GetTable("EX_FINGERPRINT");

                            function.Invoke(SapRfcDestination);

                            jj = 0;
                            foreach (IRfcStructure row in gt_table)
                            {
                                jj = jj + 1;
                                byte[] blob1 = Convert.FromBase64String(Convert.ToString(row.GetValue(0)));

                                String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp);

                                byte[] blob2 = Convert.FromBase64String(strBase64.Trim());

                                int ret = zkfp2.DBMatch(mDBHandle, blob1, blob2);
                                if (ret > 0)
                                {
                                    txtStatus.Text = "Selamat Datang!";

                                    vald = ret;
                                    break;
                                }
                                else
                                {
                                    txtStatus.Text = "Maaf and tidak dikenali";
                                }
                                zkfp2.DBClear(mDBHandle);
                            }

                            if (vald > 0)
                            {
                                // function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT");
                                // function.SetValue("MODE", "V");
                                // function.SetValue("INDX", jj);
                                // function.Invoke(SapRfcDestination);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
                        }

                        RfcSessionManager.EndContext(SapRfcDestination);
                        SapRfcDestination = null;
                    }
                }
            }
            break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }