static void Main(string[] args)
        {
            string mypath = AppDomain.CurrentDomain.BaseDirectory;
            string myfile = mypath + "DSOInput.csv";
            string res;

            try
            {
                ERPConnect.LIC.SetLic("17YZYZ5VVZ");

                string[] myLines = System.IO.File.ReadAllLines(myfile);
                string   dsoname = "ZKEDSO01"; // ZBOARD01

                R3Connection con = new R3Connection("bw2.theobald-software.com", 0, "Demouser1", "Board2016", "DE", "800");



                con.Open();

                RFCFunction delfunc = con.CreateFunction("RSDRI_ODSO_DELETE_RFC");
                delfunc.Exports["I_DELETE_ALL"].ParamValue = "X";
                delfunc.Exports["I_ODSOBJECT"].ParamValue  = dsoname;
                delfunc.Execute();

                RFCFunction insfunc = con.CreateFunction("RSDRI_ODSO_INSERT_RFC");
                insfunc.Exports["I_ODSOBJECT"].ParamValue = dsoname;

                foreach (string myline in myLines)
                {
                    if (!myline.StartsWith("Item"))
                    {
                        string[] vals = myline.Split(",".ToCharArray());

                        if (vals.Length >= 4)
                        {
                            string st = string.Empty;
                            st += vals[1].PadRight(10); // Customer 10
                            st += vals[2].PadRight(18); // Material 18
                            st += vals[3].PadRight(8);  // Date 8


                            RFCStructure neworw = insfunc.Tables["I_T_DATA"].Rows.Add();
                            neworw["DATA"] = st;
                        }
                    }
                }
                insfunc.Execute();

                int num = (int)insfunc.Imports["E_NUMROWS"].ParamValue;
                res = num + " rows inserted into DSO " + dsoname;
            }
            catch (Exception e1)
            {
                System.IO.File.WriteAllText(mypath + "UploadLog.txt", e1.ToString());
                return;
            }
            System.IO.File.WriteAllText(mypath + "UploadLog.txt", res);
        }
Beispiel #2
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();
            }
        }
Beispiel #3
0
        /// <summary>
        /// RFCs the function initialize.
        /// </summary>
        /// <param name="conn">The connection.</param>
        /// <param name="rfcName">Name of the RFC.</param>
        /// <returns>RFCFunction.</returns>
        public static RFCFunction RFCFunctionInit(this R3Connection conn, string rfcName)
        {
            var fun = conn.CreateFunction(rfcName);
            var tbs = fun.Tables;

            return(fun);
        }
        /// <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);
        }
        /// <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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Orden"></param>
        public ValidacionOrdenSAPModel ValidacionOrden(string Orden)
        {
            ValidacionOrdenSAPModel Modelo = new ValidacionOrdenSAPModel();

            try
            {
                ConectorSAP.Open();

                RFCFunction FuncionSAP = ConectorSAP.CreateFunction("ZFM_OEE_GET_ORDEN");

                FuncionSAP.Exports["IM_AUFNR"].ParamValue = "00000" + Orden;

                FuncionSAP.Execute();

                Modelo.Material    = FuncionSAP.Imports["EX_MATNR"]?.ParamValue?.ToString().Trim();
                Modelo.Descripcion = FuncionSAP.Imports["EX_MAKTX"]?.ParamValue?.ToString().TrimStart().TrimEnd();
                Modelo.Lote        = FuncionSAP.Imports["EX_CHARG"]?.ParamValue?.ToString().Trim();
                Modelo.Orden       = FuncionSAP.Imports["EX_AUFNR"]?.ParamValue?.ToString().Trim();

                if (Modelo.Orden != string.Empty)
                {
                    Modelo.EstatusValidacionOrden = 1;
                }
                else
                {
                    Modelo.EstatusValidacionOrden = 2;
                }
            }
            catch (Exception excepcion)
            {
                Modelo.EstatusValidacionOrden = -1;
                Modelo.Mensaje = excepcion.Message;
            }

            return(Modelo);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }