Ejemplo n.º 1
0
        private static void RFCUserCreate(R3Connection con, string username)
        {
            using (con)
            {
                con.Open(false);

                RFCFunction func = con.CreateFunction("BAPI_USER_CREATE1");

                func.Exports["USERNAME"].ParamValue     = username;
                func.Exports["GENERATE_PWD"].ParamValue = "X";

                RFCStructure ADDRESS = func.Exports["ADDRESS"].ToStructure();
                ADDRESS["FIRSTNAME"] = "FistName";
                ADDRESS["LASTNAME"]  = "LastName";

                RFCStructure PASSWORD = func.Exports["PASSWORD"].ToStructure();
                PASSWORD["BAPIPWD"] = "init01";

                func.Execute();

                RFCStructure pw    = func.Imports["GENERATED_PASSWORD"].ToStructure();
                string       passw = pw["BAPIPWD"].ToString();

                Console.WriteLine("Password:"******"RETURN"][0, "MESSAGE"].ToString();

                Console.WriteLine(message);
                Console.ReadLine();

                con.Close();
            }
        }
        /// <summary>
        /// 根据RFC配置信息,打开RFC链接
        /// </summary>
        /// <param name="Connection"></param>
        /// <returns></returns>
        public ReturnResult ERGetPConnection(ERPGetConnection Connection)
        {
            ReturnResult consap        = new ReturnResult();
            R3Connection ConnectionSAP = new R3Connection();

            try
            {
                string connString = BuildConneciton(Connection);
                ConnectionSAP = new R3Connection(connString);

                if (!ConnectionSAP.Ping())
                {
                    ConnectionSAP.Open();
                    consap.Status = true;
                }
            }
            catch (Exception ex)
            {
                ConnectionSAP.Close();
                consap.Message = ex.Message;
                consap.Status  = false;
                this.logHandler.Error(MethodBase.GetCurrentMethod().Name, "Call ERGetPConnection Fail: " + ex.Message);
            }
            consap.Anything = ConnectionSAP;
            return(consap);
        }
        /// <summary>
        /// 根据参数查询RFC数据
        /// </summary>
        /// <param name="refStr">查询返回信息</param>
        /// <param name="ConnectionSAP">链接信息</param>
        /// <param name="interfaceFunName">接口名称</param>
        /// <param name="lnName">料号</param>
        /// <returns></returns>
        public ReturnResult Get_RFC_Info_By_Param(ref string refStr, R3Connection ConnectionSAP, string interfaceFunName, string lnName)
        {
            ReturnResult result   = new ReturnResult();
            RFCFunction  function = null;

            try
            {
                RFCTableColumnCollection ff = new RFCTableColumnCollection();
                function = ConnectionSAP.CreateFunction(interfaceFunName);
                function.Exports["MATNR"].ParamValue = lnName;                   //查询条件(料号?)
                function.Execute();
                refStr = function.Imports["NORMT"].ParamValue.ToString().Trim(); //返回数据
                ConnectionSAP.Close();

                result.Status  = true;
                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
                this.logHandler.Error(MethodBase.GetCurrentMethod().Name, "Call Get_RFC_Info_By_Param Fail: " + ex.Message);
            }
            return(result);
        }
        /// <summary>
        /// 查询RFC数据(无查询参数)
        /// </summary>
        /// <param name="ConnectionSAP">链接信息</param>
        /// <param name="interfaceFunName">接口名称</param>
        /// <returns></returns>
        public ReturnResult Get_RFC_Info_By_NoParam(ref DataTable dataTable_put, R3Connection ConnectionSAP, string interfaceFunName)
        {
            RFCTable     rfcTable_ERR = new RFCTable();
            ReturnResult result       = new ReturnResult();
            RFCFunction  function     = null;

            try
            {
                function = ConnectionSAP.CreateFunction(interfaceFunName);

                function.Execute();
                rfcTable_ERR  = function.Tables["T_OUTTAB"];//out table
                dataTable_put = rfcTable_ERR.ToADOTable();
                ConnectionSAP.Close();
                result.Status  = true;
                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
                this.logHandler.Error(MethodBase.GetCurrentMethod().Name, "Call Get_RFC_Info_By_NoParam Fail: " + ex.Message);
            }
            return(result);
        }
Ejemplo n.º 5
0
 public void Dispose()
 {
     if (r3Connection != null && r3Connection.IsOpen)
     {
         r3Connection.Close();
     }
     r3Connection?.Dispose();
 }
Ejemplo n.º 6
0
        private static void SendIDoc(R3Connection con, string matname, bool async)
        {
            using (con)
            {
                con.Open(false);

                ERPConnect.Idocs.Idoc id = con.CreateEmptyIdoc("MATMAS05", "");

                id.SNDPRN = "ERPTEST";
                id.SNDPRT = "LS";
                id.SNDPOR = "ERPTEST";
                id.RCVPRN = "BW_STDCLNT";
                id.RCVPRT = "LS";
                id.MESTYP = "MATMAS";

                // Idoc Segement E1MARAM
                ERPConnect.Idocs.IdocSegment e1maram = id.CreateSegment("E1MARAM");
                e1maram.Fields["MATNR"].FieldValue = matname;
                e1maram.Fields["MTART"].FieldValue = "FERT";
                e1maram.Fields["MEINS"].FieldValue = "PCE";
                e1maram.Fields["MBRSH"].FieldValue = "M";
                e1maram.Fields["BRGEW"].FieldValue = "1";
                e1maram.Fields["NTGEW"].FieldValue = "1";
                e1maram.Fields["GEWEI"].FieldValue = "KG";
                id.Segments.Add(e1maram);

                // Idoc Segement E1MAKTM
                ERPConnect.Idocs.IdocSegment e1maktm = id.CreateSegment("E1MAKTM");
                e1maktm.Fields["SPRAS"].FieldValue = "E";
                e1maktm.Fields["MAKTX"].FieldValue = "my Article";
                e1maram.ChildSegments.Add(e1maktm);

                if (async)
                {
                    id.SendAndWait();
                    IdocStatus status = id.GetCurrentStatus();
                    Console.WriteLine(status.Status + "-> " + status.Description);
                }
                else
                {
                    id.Send();
                    Console.WriteLine("IDoc sent");
                }

                con.Close();
                Console.ReadLine();
            }
        }
Ejemplo n.º 7
0
        private static void BapiGetFlightList(R3Connection con)
        {
            using (con)
            {
                con.Open(false);

                BusinessObjectMethod func = con.CreateBapi("Flight", "GetList");

                func.Exports["Airline"].ParamValue = "AA";


                func.Execute();


                DataTable table = func.Tables["FLIGHT_LIST"].ToADOTable();
                con.Close();

                Console.ReadLine();
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            R3Connection con = new R3Connection();

            try
            {
                SAPConnection.Set(ref con);
                //con.UseGui = true;
                con.Open(false);
                //SAPTransaction.executeMM02(con);
                SAPTransaction.executeXD02(con);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }
        /// <summary>
        /// 根据参数查询RFC数据
        /// </summary>
        /// <param name="refStr">查询返回信息</param>
        /// <param name="ConnectionSAP">链接信息</param>
        /// <param name="interfaceFunName">接口名称</param>
        /// <param name="tbParam">料号</param>
        /// <returns></returns>
        public ReturnResult Get_RFC_Info_By_Param(ref string rfcRes, R3Connection ConnectionSAP, string interfaceFunName, DataTable tbParam)
        {
            RFCTable rfcTable_ERR = new RFCTable();

            ReturnResult result   = new ReturnResult();
            RFCFunction  function = null;


            try
            {
                RFCTableColumnCollection ff = new RFCTableColumnCollection();
                function = ConnectionSAP.CreateFunction(interfaceFunName);
                RFCTable info_table_H = function.Tables["IT_ZPPT6017"];//in table
                foreach (DataRow row in tbParam.Rows)
                {
                    RFCStructure rfcStruc_H = info_table_H.AddRow();
                    rfcStruc_H["AUFNR"] = row[0]; //MO 编号
                    rfcStruc_H["MO_NO"] = row[1]; //MO 排序
                }
                function.Execute();

                //rfcTable_ERR = function.Tables["IT_ZPPT6017"];//out table
                //dataTable_put = rfcTable_ERR.ToADOTable();
                rfcRes = function.Imports["E_FLAG"].ParamValue.ToString().Trim();
                ConnectionSAP.Close();

                result.Status  = true;
                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
                this.logHandler.Error(MethodBase.GetCurrentMethod().Name, "Call Get_RFC_Info_By_Param Fail: " + ex.Message);
            }
            return(result);
        }
Ejemplo n.º 10
0
        public List <EmployeeBasic> getEmployeeBasicList(string surname, string lastname, string job, string organisation)
        {
            string surnameSearch      = surname.Equals(string.Empty) ? "*" : surname;
            string lastnameSearch     = lastname.Equals(string.Empty) ? "*" : lastname;
            string jobSearch          = job.Equals(string.Empty) ? "*" : job;
            string organisationSearch = organisation.Equals(string.Empty) ? "*" : organisation;

            List <EmployeeBasic> result = new List <EmployeeBasic>();
            var connection = new R3Connection(_configManager.getConnectionString());

            try
            {
                connection.Open();

                var function = connection.CreateFunction(Constants.BAPI_EMPLOYEE_GETLIST);
                function.Exports[Constants.SEARCH_DATE].ParamValue    = DateTime.Now.ToShortDateString();
                function.Exports[Constants.JOB_SEARK].ParamValue      = jobSearch;
                function.Exports[Constants.JOB_SEARK].ParamValue      = jobSearch;
                function.Exports[Constants.ORG_SEARK].ParamValue      = organisationSearch;
                function.Exports[Constants.SUR_NAME_SEARK].ParamValue = surnameSearch;
                function.Exports[Constants.LST_NAME_SEARK].ParamValue = lastnameSearch;

                function.Execute();

                var table = function.Tables[Constants.EMPLOYEE_LIST];

                if (table != null && table.Rows.Count > 0)
                {
                    foreach (RFCStructure row in table.Rows)
                    {
                        var PERNR    = (string)row[Constants.PERNR];
                        var ENAME    = (string)row[Constants.ENAME];
                        var ORG_ID   = (string)row[Constants.ORG_ID];
                        var ORG_TEXT = (string)row[Constants.ORG_TEXT];
                        var JOB_ID   = (string)row[Constants.JOB_ID];
                        var JOB_TEXT = (string)row[Constants.JOB_TEXT];

                        EmployeeBasic empBasic = new EmployeeBasic()
                        {
                            Name             = ENAME,
                            JobID            = JOB_ID,
                            JobName          = JOB_TEXT,
                            OrganisationID   = ORG_TEXT,
                            OrganisationName = ORG_TEXT,
                            PersonalNumber   = PERNR
                        };

                        result.Add(empBasic);
                    }
                }
            }
            catch (Exception ex)
            {
                _loggingManager.ThrowException(ex, DOTNETSAPErrorSeverity.High);
            }
            finally
            {
                if (connection != null && connection.Ping())
                {
                    connection.Close();
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        public EmployeeDetail getEmployeeDetailedInfo(string personalNr)
        {
            EmployeeDetail result = null;

            if (!personalNr.Equals(string.Empty))
            {
                var connection = new R3Connection(_configManager.getConnectionString());

                try
                {
                    connection.Open();

                    var function = connection.CreateFunction(Constants.BAPI_PERSDATA_GETDETAILEDLIST);
                    function.Exports[Constants.EMPLOYEENUMBER].ParamValue = personalNr;

                    function.Execute();

                    var table = function.Tables[Constants.PERSONALDATA];

                    if (table != null || table.Rows.Count > 0)
                    {
                        foreach (RFCStructure row in table.Rows)
                        {
                            var NAMeOFFORMOFADD = (string)row[Constants.NAMeOFFORMOFADD];
                            var FIRSTNAME       = (string)row[Constants.FIRSTNAME];
                            var LASTNAME        = (string)row[Constants.LASTNAME];
                            var NAMEOFLANGUAGE  = (string)row[Constants.NAMEOFLANGUAGE];
                            var NAMEOFNATIONALI = (string)row[Constants.NAMEOFNATIONALITY];
                            var DATEOFBIRTH     = (string)row[Constants.DATEOFBIRTH];
                            var BIRTHPLACE      = (string)row[Constants.BIRTHPLACE];
                            var NAMEOFGENDER    = (string)row[Constants.NAMEOFGENDER];
                            var NAMEOFCOUNTRYOF = (string)row[Constants.NAMEOFCOUNTRYOF];

                            result = new EmployeeDetail()
                            {
                                Country     = NAMEOFCOUNTRYOF,
                                DateOfBith  = DATEOFBIRTH,
                                FirstName   = FIRSTNAME,
                                Gender      = NAMEOFGENDER,
                                Language    = NAMEOFLANGUAGE,
                                LastName    = LASTNAME,
                                NamePrefix  = NAMeOFFORMOFADD,
                                Nationality = NAMEOFNATIONALI,
                                PlaceOfBith = BIRTHPLACE
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    _loggingManager.ThrowException(ex, DOTNETSAPErrorSeverity.High);
                }
                finally
                {
                    if (connection != null && connection.Ping())
                    {
                        connection.Close();
                    }
                }
            }
            return(result);
        }