Ejemplo n.º 1
0
        public void MakeNonSsoConnection()
        {
            try
            {
                r3Connection = new R3Connection();

                r3Connection.Client            = sapConfig.SapClient;
                r3Connection.Host              = sapConfig.SapHost;
                r3Connection.SystemNumber      = sapConfig.SapSystemNumber;
                r3Connection.UserName          = sapConfig.SapNonSsoUserName;
                r3Connection.Password          = sapConfig.SapNonSsoPassword;
                r3Connection.LogonGroup        = sapConfig.SapLogonGroup;
                r3Connection.Language          = sapConfig.SapLanguage;
                r3Connection.MessageServer     = sapConfig.SapMessageServer;
                r3Connection.Protocol          = sapConfig.SapProtocol;
                r3Connection.SID               = sapConfig.SapSid;
                r3Connection.UsesLoadBalancing = sapConfig.SapUsesLoadBalancing;
                Log.Information("Trying to Connect User - " + WindowsIdentity.GetCurrent().Name + "  to SAP using NON SSO");
                r3Connection.Open();
            }
            catch (Exception exception)
            {
                r3Connection = null;
                Log.Error("SAP Error " + exception, "Could not create R3Connection");
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
0
        private static void ExecuteSAPQuery(R3Connection con)
        {
            using (con)
            {
                con.Open(false);

                // Create Query object Query q;
                Query q;
                try
                {
                    q = con.CreateQuery(WorkSpace.GlobalArea, "/SAPQUERY/QD", "CONNECTIONS_02");
                    //q.Variant = "ALL";
                    q.MaxRows = 1000;
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1.ToString());
                    return;
                }

                // Add a criteria (in this case the material number)
                //q.SelectionParameters["SP$00017"].Ranges.Add(Sign.Include, RangeOption.Equals, "100-100");

                // Add a second criteria (in this case the currency)
                //q.SelectionParameters["S_WAERS"].Ranges.Add(Sign.Include, RangeOption.Equals, "EUR");

                // Run the Query
                q.Execute();

                // Bind result to datagrid
                DataTable table = q.Result;

                Console.Read();
            }
        }
        /// <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);
        }
Ejemplo n.º 5
0
        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);
        }
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
 static void Main(string[] args)
 {
     using (R3Connection con = new R3Connection())
     {
         con.Host                            = "saperp.theobald.local";
         con.SystemNumber                    = 0;
         con.Client                          = "800";
         con.Language                        = "DE";
         con.SNCSettings.Enabled             = true;
         con.SNCSettings.PartnerName         = "p:[email protected]";
         con.SNCSettings.Mechanism           = SNCMechanism.Kerberos5;
         con.SNCSettings.QualityOfProtection = SNCQualityOfProtection.Maximum;
         con.Open();
         // do something with con
         Console.WriteLine("SSO Connection Succesful!");
     }
 }
Ejemplo n.º 8
0
        private static void GetBWCube(R3Connection con, string name)
        {
            using (con)
            {
                con.Open(false);
                //0,0D_NW_CHANN,Distribution Channel, C,255,0
                //1,0D_NW_CNTRY,Country,C,255,0
                //2,0D_NW_CODE,Company code, C,255,0
                //3,0D_NW_DIV,Division,C,255,0
                //4,0D_NW_PAYER,Payer,C,255,0
                //5,0D_NW_PLANT,Plant,C,255,0
                //6,0D_NW_PROD,Product,C,255,0
                //7,0D_NW_REGIO,Region,C,255,0
                //8,0D_NW_SGRP,Sales Group, C,255,0
                //9,0D_NW_SHIP,Ship - to Party,C,255,0
                //10, 0D_NW_SOLD,Sold - to Party,C,255,0
                //11, 0D_NW_SORG,Sales Organization, C,255,0
                //12, 0CALYEAR,Calendar Year, C,255,0
                //13, 0MEASURES0000000000000009_0D9NW9NETV000000000000010,Net Value stat curr, P,16,0
                //14, 0MEASURES0000000000000009_0D9NW9OORV000000000000010,Open order stat curr, P,16,0

                BWCube query = con.CreateBWCube(name);
                query.Dimensions["0D_NW_CHANN"].SelectForFlatMDX = true;
                query.Dimensions["0D_NW_CNTRY"].SelectForFlatMDX = true;
                query.Dimensions["0D_NW_CODE"].SelectForFlatMDX  = true;
                query.Dimensions["0D_NW_DIV"].SelectForFlatMDX   = true;
                query.Dimensions["0D_NW_PAYER"].SelectForFlatMDX = true;
                query.Dimensions["0D_NW_PLANT"].SelectForFlatMDX = true;

                query.Measures[0].SelectForFlatMDX = true;
                query.Measures[1].SelectForFlatMDX = true;
                query.Measures[2].SelectForFlatMDX = true;
                query.Measures[3].SelectForFlatMDX = true;


                //query.Variables["MAT01"].SingleRange.LowValue = this.txtMatNr.Text;

                DataTable table = query.Execute();

                Console.Read();
            }
        }
Ejemplo n.º 9
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.º 10
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>
        ///
        /// </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);
        }
Ejemplo n.º 12
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.º 13
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);
        }