Beispiel #1
0
        public static IRfcTable SAPExecuteDeulTableData(Hashtable[] arrht1, string Function_Name, string RfcStructure_Name, string SetTable_Name, string GetTable_Name)
        {
            RfcConfigParameters configParam = GetConfigParam();
            RfcDestination      destination = RfcDestinationManager.GetDestination(configParam);
            IRfcFunction        function    = destination.Repository.CreateFunction(Function_Name);

            IRfcTable rfcTable = function.GetTable(SetTable_Name);

            for (int i = 0; i < arrht1.Length; i++)
            {
                RfcStructureMetadata strMeta      = destination.Repository.GetStructureMetadata(RfcStructure_Name);
                IRfcStructure        rfcStructure = strMeta.CreateStructure();

                IDictionaryEnumerator ie = arrht1[i].GetEnumerator();

                while (ie.MoveNext())
                {
                    if (ie.Value.ToString().Length <= 4000)
                    {
                        rfcStructure.SetValue(ie.Key.ToString(), ie.Value);
                    }
                }

                rfcTable.Append(rfcStructure);
            }

            function.Invoke(destination);

            IRfcTable rfcTable2 = function.GetTable(GetTable_Name);

            return(rfcTable2);
        }
Beispiel #2
0
        public IRfcStructure CreateStructure(RfcStructureMetadata metadata, object parameterObject)
        {
            if (parameterObject == null)
            {
                return(null);
            }

            IRfcStructure structure = metadata.CreateStructure();
            Type          type      = parameterObject.GetType();

            EnsureTypeIsCached(type);

            for (int i = 0; i < metadata.FieldCount; i++)
            {
                string       fieldName = metadata[i].Name;
                PropertyInfo property  = null;

                object formattedValue = null;
                if (typeProperties[type].TryGetValue(fieldName.ToLower(), out property))
                {
                    object value = property.GetValue(parameterObject, null);
                    formattedValue = this.ToRemoteValue(metadata[i].GetAbapDataType(), value);
                }
                else if (string.IsNullOrEmpty(fieldName))
                {
                    formattedValue = this.ToRemoteValue(metadata[i].GetAbapDataType(), parameterObject);
                }

                structure.SetValue(fieldName, formattedValue);
            }
            return(structure);
        }
Beispiel #3
0
        public static string SAPExecuteStructureData(Hashtable ht, string Function_Name, string RfcStructure_Name, string param1)
        {
            RfcConfigParameters configParam = GetConfigParam();
            RfcDestination      destination = RfcDestinationManager.GetDestination(configParam);
            IRfcFunction        function    = destination.Repository.CreateFunction(Function_Name);

            RfcStructureMetadata strMeta      = destination.Repository.GetStructureMetadata(RfcStructure_Name);
            IRfcStructure        rfcStructure = strMeta.CreateStructure();


            IDictionaryEnumerator ie = ht.GetEnumerator();

            while (ie.MoveNext())
            {
                if (ie.Value.ToString().Length <= 4000)
                {
                    rfcStructure.SetValue(ie.Key.ToString(), ie.Value);
                }
            }

            function.SetValue(param1, rfcStructure);
            function.Invoke(destination);

            string returnCode = function.GetString("EV_E_TYPE");

            return(returnCode);
        }
Beispiel #4
0
        public bool EnviarDatosCobranza(DataTable dt)
        {
            RfcConfigParameters rfc = new RfcConfigParameters();

            rfc.Add(RfcConfigParameters.Name, ConfigurationManager.AppSettings["Name"]);
            rfc.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["AppServerHost"]);
            rfc.Add(RfcConfigParameters.Client, ConfigurationManager.AppSettings["Client"]);
            rfc.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["User"]);
            rfc.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["Password"]);
            rfc.Add(RfcConfigParameters.SystemNumber, "00");
            rfc.Add(RfcConfigParameters.Language, "ES");
            rfc.Add(RfcConfigParameters.PoolSize, "5");
            rfc.Add(RfcConfigParameters.MaxPoolSize, "100");
            rfc.Add(RfcConfigParameters.IdleTimeout, "900");
            RfcDestination rfcDest = null;

            try
            {
                rfcDest = RfcDestinationManager.GetDestination(rfc);
            }
            catch (Exception e)
            {
                e.ToString();
            }

            IRfcFunction         function = rfcDest.Repository.CreateFunction("ZSD_REXSAP_010"); // A la espera del nombre de la funcio
            IRfcTable            doc      = function.GetTable("TI_DOCREXSAP");                   //A la espera del nombre de la tabla
            RfcStructureMetadata metadata = doc.Metadata.LineType;

            List <string> nombresColumna = new List <string>();


            for (int i = 0; i < metadata.FieldCount; i++)
            {
                nombresColumna.Add(doc.GetElementMetadata(i).Name);
            }
            foreach (DataRow row in dt.Rows)
            {
                doc.Append();

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (ExisteNombreColumna(nombresColumna, dt.Columns[i].ColumnName))
                    {
                        doc.SetValue(dt.Columns[i].ColumnName, row[dt.Columns[i].ColumnName]);
                    }
                }
            }


            try {
                function.Invoke(rfcDest);
                return(true);
            } catch (Exception e) {
                return(false);
            }
        }
Beispiel #5
0
        private Boolean ImportInvoice(String databaseName, DocumentCached invoice, out String documentNumber, out String errorMessage)
        {
            errorMessage   = String.Empty;
            documentNumber = String.Empty;

            try
            {
                IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST");
                fReadTable.SetValue("CUSTOMER", ("0000000" + invoice.CustomerCode).Right(10));
                fReadTable.SetValue("SALES_ORG", invoice.VLCompany);
                fReadTable.SetValue("PURCH_DATE", invoice.DocDate);
                fReadTable.SetValue("PURCH_NO_C", invoice.Comment);

                foreach (DocumentLineCached line in invoice.Lines)
                {
                    RfcStructureMetadata metaData         = dest.Repository.GetStructureMetadata("ZORDERLINE");
                    IRfcStructure        structConditions = metaData.CreateStructure();

                    structConditions.SetValue("ITM_NUMBER", ("0000" + line.LineNum.ToString() + "0").Right(6));
                    structConditions.SetValue("MATERIAL", line.ItemCode);                     // C => Certificate
                    structConditions.SetValue("TARGET_QTY", line.Quantity);
                    structConditions.SetValue("SALES_UNIT", line.UnitOfMeasure);
                    structConditions.SetValue("COND_VALUE", line.Price);
                    structConditions.SetValue("CURRENCY", line.Currency);
                    structConditions.SetValue("SHORT_TEXT", line.ShortText);

                    IRfcTable tblItems = fReadTable.GetTable("ORDERLINE");
                    tblItems.Append(structConditions);
                    fReadTable.SetValue("ORDERLINE", tblItems);
                }


                fReadTable.Invoke(dest);
                String        result  = (String)fReadTable.GetValue("SALESDOCUMENT");
                IRfcStructure result2 = (IRfcStructure)fReadTable.GetValue("RETURN");

                documentNumber = result.ToString();
                errorMessage   = result2[3].ToString().Replace("FIELD MESSAGE=", "");


                if (String.IsNullOrEmpty(documentNumber) || !String.IsNullOrEmpty(errorMessage))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return(true);
        }
Beispiel #6
0
        public IRfcTable ToSapObject(string name)
        {
            Type type = typeof(T);
            RfcStructureMetadata sMeta = SapConnections.Get(name).Repository.GetStructureMetadata(typeof(T).Name);
            RfcTableMetadata     tMeta = new RfcTableMetadata("", sMeta);
            IRfcTable            t     = tMeta.CreateTable();

            for (int i = 0; i < this.Count; i++)
            {
                t.Insert(((ISapStructure)this[i]).ToSapObject(name));
            }
            return(t);
        }
Beispiel #7
0
        public static string SAPExecuteTableData(Hashtable[] arrht, Hashtable ImportData, string Function_Name, string RfcStructure_Name, string Table_Name)
        {
            RfcConfigParameters configParam = GetConfigParam();
            RfcDestination      destination = RfcDestinationManager.GetDestination(configParam);
            IRfcFunction        function    = destination.Repository.CreateFunction(Function_Name);

            IRfcTable rfcTable = function.GetTable(Table_Name);

            for (int i = 0; i < arrht.Length; i++)
            {
                RfcStructureMetadata strMeta      = destination.Repository.GetStructureMetadata(RfcStructure_Name);
                IRfcStructure        rfcStructure = strMeta.CreateStructure();

                if (arrht[i] == null)
                {
                    continue;
                }

                IDictionaryEnumerator ie = arrht[i].GetEnumerator();

                while (ie.MoveNext())
                {
                    if (ie.Value.ToString().Length <= 4000)
                    {
                        rfcStructure.SetValue(ie.Key.ToString(), ie.Value);
                    }
                }

                rfcTable.Append(rfcStructure);
            }

            if (ImportData.Count > 0)
            {
                IDictionaryEnumerator ie = ImportData.GetEnumerator();

                while (ie.MoveNext())
                {
                    if (ie.Value.ToString().Length <= 4000)
                    {
                        function.SetValue(ie.Key.ToString(), ie.Value);
                    }
                }
            }

            function.Invoke(destination);

            string returnCode = function.GetString("E_VBELN");

            return(returnCode);
        }
Beispiel #8
0
        public FunctionResult ExecuteInsert(string functionName, List <NTable> parameters, List <string> tableNames)
        {
            try
            {
                _function = _destination.Repository.CreateFunction(functionName);

                for (int i = 0; i < tableNames.Count; i++)
                {
                    RfcStructureMetadata metaData = _destination.Repository.GetStructureMetadata(parameters[i].StructureName);

                    IRfcTable tblInput = _function.GetTable(tableNames[i]);

                    foreach (DataRow row in parameters[i].Parameters.Rows)
                    {
                        IRfcStructure structRow = metaData.CreateStructure();

                        foreach (DataColumn column in parameters[i].Parameters.Columns)
                        {
                            object obj = row[column];
                            structRow.SetValue(column.ToString(), obj);
                        }

                        tblInput.Append(structRow);
                    }
                }

                RfcSessionManager.BeginContext(_destination);
                _function.Invoke(_destination);

                IRfcTable returnTable = _function.GetTable("NOTESRETURN");

                return(new FunctionResult
                {
                    IsSuccess = true,
                    Data = new List <object> {
                        returnTable
                    }
                });
            }
            catch (Exception ex)
            {
                return(new FunctionResult
                {
                    IsSuccess = false,
                    ErrorMessage = ex.ToString()
                });
            }
        }
Beispiel #9
0
        public override RfcPreparedFunction Prepare()
        {
            try
            {
                this.function = this.repository.CreateFunction(this.FunctionName);
                foreach (var parameter in this.Parameters)
                {
                    int idx = this.function.Metadata.TryNameToIndex(parameter.Name);
                    if (idx == -1)
                    {
                        throw new UnknownRfcParameterException(parameter.Name, this.FunctionName);
                    }

                    RfcDataType pType = this.function.Metadata[idx].DataType;
                    switch (pType)
                    {
                    case RfcDataType.STRUCTURE:
                        RfcStructureMetadata structureMetadata = this.function.GetStructure(idx).Metadata;
                        IRfcStructure        structure         = this.structureMapper.CreateStructure(structureMetadata, parameter.Value);
                        this.function.SetValue(parameter.Name, structure);
                        break;

                    case RfcDataType.TABLE:
                        RfcTableMetadata tableMetadata = this.function.GetTable(idx).Metadata;
                        IRfcTable        table         = this.structureMapper.CreateTable(tableMetadata, parameter.Value);
                        this.function.SetValue(parameter.Name, table);
                        break;

                    default:
                        object formattedValue = this.structureMapper.ToRemoteValue(this.function.Metadata[idx].GetAbapDataType(), parameter.Value);
                        this.function.SetValue(parameter.Name, formattedValue);
                        break;
                    }
                }
                return(this);
            }
            catch (Exception ex)
            {
                if (ex.GetBaseException() is SharpRfcException)
                {
                    throw ex;
                }

                throw new SharpRfcCallException(ex.Message, function == null ? this.FunctionName : function.ToString(), ex);
            }
        }
        private double ProductInfoGetRealtimeStock(string branchCode, string warehouseCode, string productCode, string uom)
        {
            RfcDestination sapRfcDestination = SapHelper.Destination;
            RfcRepository  sapRfcRepository  = sapRfcDestination.Repository;

            RfcRepository repo       = sapRfcRepository;
            string        bapiName   = "BAPI_MATERIAL_AVAILABILITY";
            IRfcFunction  exportBapi = repo.CreateFunction(bapiName);

            exportBapi.SetValue("PLANT", "");
            exportBapi.SetValue("MATERIAL", "");
            exportBapi.SetValue("UNIT", "");
            exportBapi.SetValue("CHECK_RULE", "");
            exportBapi.SetValue("STGE_LOC", "");
            exportBapi.SetValue("BATCH", "");
            exportBapi.SetValue("CUSTOMER", "");
            exportBapi.SetValue("DOC_NUMBER", "");
            exportBapi.SetValue("ITM_NUMBER", "");
            exportBapi.SetValue("WBS_ELEM", "");
            exportBapi.SetValue("STOCK_IND", "");
            exportBapi.SetValue("DEC_FOR_ROUNDING", 0);
            exportBapi.SetValue("DEC_FOR_ROUNDING_X", "");
            exportBapi.SetValue("READ_ATP_LOCK", "");
            exportBapi.SetValue("READ_ATP_LOCK_X", "");

            IRfcStructure        articol;
            RfcStructureMetadata am = repo.GetStructureMetadata("BAPIMGVMATNR");

            articol = am.CreateStructure();
            exportBapi.SetValue("MATERIAL_EVG", articol);

            exportBapi.SetValue("MATERIAL", FormatedProductCode(productCode));
            exportBapi.SetValue("PLANT", branchCode);
            exportBapi.SetValue("UNIT", uom);
            exportBapi.SetValue("STGE_LOC", warehouseCode);
            exportBapi.SetValue("CHECK_RULE", "B");
            exportBapi.SetValue("ITM_NUMBER", "000000");

            exportBapi.Invoke(sapRfcDestination);
            IRfcTable detail = exportBapi.GetTable("WMDVEX");


            return(detail.RowCount);
        }
Beispiel #11
0
        public static IRfcStructure CreateRFCStructure(Dictionary <string, object> item, RfcDestination destination, string structureName)
        {
            RfcStructureMetadata metaData  = destination.Repository.GetStructureMetadata(structureName);
            IRfcStructure        structure = metaData.CreateStructure();

            foreach (var key in item.Keys)
            {
                if (GetDataType(structure[key].Metadata.DataType) == typeof(DateTime))
                {
                    structure.SetValue(key, ((DateTime)item[key]).ToString(kSAPStructureDateFormat));
                }
                else if (GetDataType(structure[key].Metadata.DataType) == typeof(TimeSpan))
                {
                    TimeSpan t = (TimeSpan)item[key];
                    structure.SetValue(key, string.Format(kSAPStructureTimeFormat, t.Hours, t.Minutes, t.Seconds));
                }
                else
                {
                    structure.SetValue(key, item[key]);
                }
            }

            return(structure);
        }
Beispiel #12
0
        private Boolean ImportInvoice2(String databaseName, DocumentCached invoice)
        {
            IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST");

            fReadTable.SetValue("CUSTOMER", "0000008289");
            fReadTable.SetValue("SALES_ORG", "ZW01");
            fReadTable.SetValue("PURCH_DATE", DateTime.Now);
            fReadTable.SetValue("PURCH_NO_C", "TEST ZZBAPI_DEBIT_MEMO_REQUEST");

            RfcStructureMetadata metaData         = dest.Repository.GetStructureMetadata("ZORDERLINE");
            IRfcStructure        structConditions = metaData.CreateStructure();

            structConditions.SetValue("ITM_NUMBER", "000010");
            structConditions.SetValue("MATERIAL", "C");             // C => Certificate
            structConditions.SetValue("TARGET_QTY", 10);
            structConditions.SetValue("SALES_UNIT", "ST");
            structConditions.SetValue("COND_VALUE", 16);
            structConditions.SetValue("CURRENCY", "EUR");
            structConditions.SetValue("SHORT_TEXT", "test");

            IRfcTable tblItems = fReadTable.GetTable("ORDERLINE");

            tblItems.Append(structConditions);
            fReadTable.SetValue("ORDERLINE", tblItems);



            fReadTable.Invoke(dest);
            var result  = fReadTable.GetValue("SALESDOCUMENT");
            var result2 = fReadTable.GetValue("RETURN");

            Console.WriteLine(result.ToString());
            Console.ReadLine();

            return(true);
        }
Beispiel #13
0
        public IRfcTable CreateTable(RfcTableMetadata metadata, object parameterObject)
        {
            IRfcTable            table             = metadata.CreateTable();
            RfcStructureMetadata structureMetadata = metadata.LineType;

            IEnumerable enumerable = parameterObject as IEnumerable;

            if (enumerable == null)
            {
                IRfcStructure row = CreateStructure(structureMetadata, parameterObject);
                table.Append(row);
            }
            else
            {
                var enumerator = enumerable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    object        current = enumerator.Current;
                    IRfcStructure row     = CreateStructure(structureMetadata, current);
                    table.Append(row);
                }
            }
            return(table);
        }
Beispiel #14
0
        /// <summary>
        /// 读取RFC函数的全部信息
        /// </summary>
        /// <param name="sysName"></param>
        /// <param name="funame"></param>
        /// <returns></returns>
        public static RfcFunctionMetaAsList GetFuncMetaAsList(string sysName, string funame)
        {
            funame = funame.ToUpper().Trim();
            RfcFunctionMetadata   MetaData = GetRfcFunctionMetadata(sysName, funame);
            RfcFunctionMetaAsList metaList = new RfcFunctionMetaAsList();

            // metaList.Import.Add(
            //根据参数的方向,分为四种(CHANGING,EXPORT,IMPORT,TABLES);
            for (int i = 0; i < MetaData.ParameterCount; i++)
            {
                RfcParameterMetadata pMetadata = MetaData[i];
                FunctionField        field     = null;
                String dataTypeName            = String.Empty;
                if (pMetadata.DataType == RfcDataType.STRUCTURE)
                {
                    RfcContainerMetadata <RfcFieldMetadata> meta = pMetadata.ValueMetadataAsStructureMetadata;
                    dataTypeName = meta.Name;
                }
                else if (pMetadata.DataType == RfcDataType.TABLE)
                {
                    RfcContainerMetadata <RfcFieldMetadata> meta = pMetadata.ValueMetadataAsTableMetadata;
                    RfcTableMetadata tablem = pMetadata.ValueMetadataAsTableMetadata;
                    dataTypeName = tablem.LineType.Name;
                }
                field = new FunctionField(pMetadata.Name, pMetadata.Direction.ToString(), pMetadata.DataType.ToString(), pMetadata.Decimals, pMetadata.DefaultValue, pMetadata.NucLength, pMetadata.Optional, pMetadata.Documentation, dataTypeName);
                switch (pMetadata.Direction)
                {
                //创建四个方向的参数列表
                case RfcDirection.CHANGING:
                    metaList.Changing.Add(pMetadata.Name, field);
                    break;

                case RfcDirection.EXPORT:
                    metaList.Export.Add(pMetadata.Name, field);
                    break;

                case RfcDirection.IMPORT:
                    metaList.Import.Add(pMetadata.Name, field);
                    break;

                case RfcDirection.TABLES:
                    metaList.Tables.Add(pMetadata.Name, field);
                    break;
                }
                if (pMetadata.DataType == RfcDataType.STRUCTURE)
                {
                    RfcContainerMetadata <RfcFieldMetadata> fieldMeta = pMetadata.ValueMetadataAsStructureMetadata;
                    if (!metaList.StructureDetail.Keys.Contains(fieldMeta.Name))
                    {
                        RfcStructureMetadata  strucmeta = pMetadata.ValueMetadataAsStructureMetadata;
                        List <StructureField> fieldList = new List <StructureField>();
                        for (int f = 0; f < strucmeta.FieldCount; f++)
                        {
                            RfcFieldMetadata fieldm         = strucmeta[f];
                            StructureField   structureField = new StructureField(fieldm.Name, fieldm.DataType.ToString(), fieldm.Decimals, fieldm.NucLength, fieldm.Documentation);
                            fieldList.Add(structureField);
                        }
                        metaList.StructureDetail.Add(fieldMeta.Name, fieldList);
                    }
                }
                else if (pMetadata.DataType == RfcDataType.TABLE)
                {
                    RfcTableMetadata tableMeta = pMetadata.ValueMetadataAsTableMetadata;
                    if (!metaList.StructureDetail.Keys.Contains(tableMeta.LineType.Name))
                    {
                        List <StructureField> tableFieldList = new List <StructureField>();
                        for (int f = 0; f < tableMeta.LineType.FieldCount; f++)
                        {
                            RfcFieldMetadata fieldm         = tableMeta.LineType[f];
                            StructureField   structureField = new StructureField(fieldm.Name, fieldm.DataType.ToString(), fieldm.Decimals, fieldm.NucLength, fieldm.Documentation);
                            tableFieldList.Add(structureField);
                        }
                        metaList.StructureDetail.Add(tableMeta.LineType.Name, tableFieldList);
                    }
                }
            }
            return(metaList);
        }
Beispiel #15
0
        /// <summary>
        /// 读取RFCFunction的所有元数据,并以DataTable的形式输出
        /// </summary>
        /// <param name="sysName"></param>
        /// <param name="funame"></param>
        /// <returns></returns>
        public static FunctionMetaAsDataTable GetRfcFuncMetaAsDataTable(string sysName, string funame)
        {
            FunctionMetaAsDataTable metaTable = null;

            try
            {
                RfcFunctionMetadata MetaData = GetRfcFunctionMetadata(sysName, funame);
                metaTable = new FunctionMetaAsDataTable();
                DataTable dtImport   = FunctionMetaAsDataTable.ParameterDefinitionView();
                DataTable dtExport   = dtImport.Copy();
                DataTable dtChanging = dtImport.Copy();
                DataTable dtTables   = dtImport.Copy();
                //根据参数的方向,分为四种(CHANGING,EXPORT,IMPORT,TABLES);
                for (int i = 0; i < MetaData.ParameterCount; i++)
                {
                    RfcParameterMetadata pMetadata = MetaData[i];
                    switch (pMetadata.Direction)
                    {
                    //创建四个方向的参数列表
                    case RfcDirection.CHANGING:
                        AddMetadataToTable(ref pMetadata, ref dtChanging);
                        break;

                    case RfcDirection.EXPORT:
                        AddMetadataToTable(ref pMetadata, ref dtExport);
                        break;

                    case RfcDirection.IMPORT:
                        AddMetadataToTable(ref pMetadata, ref dtImport);
                        break;

                    case RfcDirection.TABLES:
                        AddMetadataToTable(ref pMetadata, ref dtTables);
                        break;
                    }
                    if (pMetadata.DataType == RfcDataType.STRUCTURE)
                    {
                        RfcStructureMetadata strucmeta = pMetadata.ValueMetadataAsStructureMetadata;
                        RfcContainerMetadata <RfcFieldMetadata> meta = pMetadata.ValueMetadataAsStructureMetadata;
                        if (!metaTable.StructureDetail.Keys.Contains(meta.Name))
                        {
                            //在这里创建结构体的定义表格
                            DataTable dtStructure = FunctionMetaAsDataTable.StructDefinitionView();
                            for (int f = 0; f < strucmeta.FieldCount; f++)
                            {
                                DataRow          dr     = dtStructure.NewRow();
                                RfcFieldMetadata fieldm = strucmeta[f];
                                dr["Name"]          = fieldm.Name;
                                dr["DataType"]      = fieldm.DataType.ToString();
                                dr["Decimals"]      = fieldm.Decimals;
                                dr["Length"]        = fieldm.NucLength;
                                dr["Documentation"] = fieldm.Documentation;
                                dtStructure.Rows.Add(dr);
                            }
                            metaTable.StructureDetail.Add(meta.Name, dtStructure);
                        }
                        if (!metaTable.InputTable.Keys.Contains(pMetadata.Name))
                        {
                            //用于输入数据的DataTable;
                            DataTable dtInput = new DataTable();
                            for (int f = 0; f < strucmeta.FieldCount; f++)
                            {
                                RfcFieldMetadata fieldm  = strucmeta[f];
                                DataColumn       dc      = null;
                                String           colName = fieldm.Name;
                                dc           = new DataColumn(colName, Type.GetType("System.String"));
                                dc.MaxLength = fieldm.NucLength;
                                dc.Caption   = fieldm.Documentation;
                                dtInput.Columns.Add(dc);
                            }
                            metaTable.InputTable.Add(pMetadata.Name, dtInput);
                        }
                    }
                    else if (pMetadata.DataType == RfcDataType.TABLE)
                    {
                        //在这里创建表的定义明细表格
                        RfcTableMetadata tablem = pMetadata.ValueMetadataAsTableMetadata;
                        if (!metaTable.StructureDetail.Keys.Contains(tablem.LineType.Name))
                        {
                            DataTable dtTable = FunctionMetaAsDataTable.StructDefinitionView();
                            for (int f = 0; f < tablem.LineType.FieldCount; f++)
                            {
                                DataRow          dr     = dtTable.NewRow();
                                RfcFieldMetadata fieldm = tablem.LineType[f];
                                dr["Name"]          = fieldm.Name;
                                dr["DataType"]      = fieldm.DataType;
                                dr["Decimals"]      = fieldm.Decimals;
                                dr["Length"]        = fieldm.NucLength;
                                dr["Documentation"] = fieldm.Documentation;
                                dtTable.Rows.Add(dr);
                            }
                            metaTable.StructureDetail.Add(tablem.LineType.Name, dtTable);
                        }
                        if (!metaTable.InputTable.Keys.Contains(pMetadata.Name))
                        {
                            //用于输入数据的DataTable;
                            DataTable dtInput = new DataTable();
                            for (int f = 0; f < tablem.LineType.FieldCount; f++)
                            {
                                RfcFieldMetadata fieldm  = tablem.LineType[f];
                                DataColumn       dc      = null;
                                String           colName = fieldm.Name;
                                dc           = new DataColumn(colName, Type.GetType("System.String"));
                                dc.MaxLength = fieldm.NucLength;
                                dc.Caption   = fieldm.Documentation;
                                dtInput.Columns.Add(dc);
                            }
                            metaTable.InputTable.Add(pMetadata.Name, dtInput);
                        }
                    }
                }
                metaTable.Import   = dtImport;
                metaTable.Export   = dtExport;
                metaTable.Changing = dtChanging;
                metaTable.Tables   = dtTables;
            }
            catch (Exception ee)
            {
                metaTable = null;
                throw new SAPException(ee.Message);
            }
            return(metaTable);
        }
Beispiel #16
0
        public static Hashtable SAPExecuteTableData_Common(Hashtable[] arrht, Hashtable ImportData, string Function_Name, string RfcStructure_Name, string Table_Name, string GetTable_Name, string GetTable_Name2)
        {
            RfcConfigParameters configParam = GetConfigParam();
            RfcDestination      destination = RfcDestinationManager.GetDestination(configParam);
            IRfcFunction        function    = destination.Repository.CreateFunction(Function_Name);

            IRfcTable rfcTable = function.GetTable(Table_Name);

            for (int i = 0; i < arrht.Length; i++)
            {
                RfcStructureMetadata strMeta      = destination.Repository.GetStructureMetadata(RfcStructure_Name);
                IRfcStructure        rfcStructure = strMeta.CreateStructure();

                //if (arrht[i] == null)
                //    continue;

                IDictionaryEnumerator ie = arrht[i].GetEnumerator();

                while (ie.MoveNext())
                {
                    if (ie.Value.ToString().Length <= 4000)
                    {
                        rfcStructure.SetValue(ie.Key.ToString(), ie.Value);
                    }
                }

                rfcTable.Append(rfcStructure);
            }

            if (ImportData.Count > 0)
            {
                IDictionaryEnumerator ie = ImportData.GetEnumerator();

                while (ie.MoveNext())
                {
                    if (ie.Value.ToString().Length <= 4000)
                    {
                        function.SetValue(ie.Key.ToString(), ie.Value);
                    }
                }
            }

            function.Invoke(destination);
            IRfcTable rfcTable2 = function.GetTable(GetTable_Name);
            IRfcTable rfcTable3 = null;

            if (GetTable_Name2 != null)
            {
                rfcTable3 = function.GetTable(GetTable_Name2);
            }

            Hashtable ht = new Hashtable();

            switch (Function_Name)
            {
            case "ZMM_SKD_PO_AND_GR":
                ht.Add("I_EBELN", function.GetString("I_EBELN"));
                ht.Add("I_MBLNR", function.GetString("I_MBLNR"));
                ht.Add("FT_RETURN_PO", rfcTable2);
                ht.Add("FT_RETURN_GR", rfcTable3);
                break;

            case "ZMM_SKD_PO":
                ht.Add("I_EBELN", function.GetString("I_EBELN"));
                ht.Add("FT_RETURN_PO", rfcTable2);
                break;

            case "ZMM_SKD_BAPI_GOODSMVT_CREATE":
                ht.Add("I_MBLNR", function.GetString("I_MBLNR"));
                ht.Add("FT_RETURN_GR", rfcTable2);
                break;
            }

            return(ht);
        }
Beispiel #17
0
        public Location LocationGetByCode(string locationCode, string warehouseCode)
        {
            Location location = null;

            //using (var db = new DbManager("HandHeldDB"))
            //{
            //    var reader = db.SetCommand(GetSql(43),
            //   db.Parameter("@LocationCode", locationCode),
            //   db.Parameter("@WarehouseCode", warehouseCode))
            //   .ExecuteReader();
            //    while (reader.Read())
            //    {
            //        location = new Location { Code = (string)reader["LocationCode"], WarehouseCode = (string)reader["WarehouseCode"] };
            //    }
            //}
            //var conn = new DBCon.DBSQLDataContext();
            //var locationli = conn.ProductLocations.Where(x => x.LocationCode == locationCode && x.WarehouseCode == warehouseCode).ToList();
            //foreach (var item in locationli)
            //{
            //    location = new Location { Code = item.LocationCode, WarehouseCode = item.WarehouseCode };
            //}
            if (location == null)
            {
                RfcDestination sapRfcDestination = SapHelper.Destination;
                RfcRepository  sapRfcRepository  = sapRfcDestination.Repository;

                char          delimiter  = ':';
                RfcRepository repo       = sapRfcRepository;
                string        bapiName   = "RFC_READ_TABLE";
                IRfcFunction  exportBapi = repo.CreateFunction(bapiName);
                exportBapi.SetValue("QUERY_TABLE", "ZLOCSTRC");
                exportBapi.SetValue("DELIMITER", delimiter);
                exportBapi.SetValue("NO_DATA", "");
                exportBapi.SetValue("ROWSKIPS", 0);
                exportBapi.SetValue("ROWCOUNT", 0);

                RfcStructureMetadata rfcDbOpt = repo.GetStructureMetadata("RFC_DB_OPT");
                var opt = rfcDbOpt.CreateStructure();
                //opt.SetValue("TEXT", @"(APRVFLAG = 'C') AND (USEFLAG = 'X')");
                opt.SetValue("TEXT", string.Format(" (BINLOC = '{0}') ", locationCode));
                var tableOptions = exportBapi.GetTable("OPTIONS");
                tableOptions.Append(opt);

                var                  table = exportBapi.GetTable("FIELDS");
                IRfcStructure        articol;
                RfcStructureMetadata am = repo.GetStructureMetadata("RFC_DB_FLD");
                articol = am.CreateStructure();
                articol.SetValue("FIELDNAME", "BINLOC");
                table.Append(articol);
                articol = am.CreateStructure();
                articol.SetValue("FIELDNAME", "LGORT");
                table.Append(articol);
                articol = am.CreateStructure();
                articol.SetValue("FIELDNAME", "USEFLAG");
                table.Append(articol);

                exportBapi.SetValue("FIELDS", table);
                exportBapi.SetValue("OPTIONS", tableOptions);
                exportBapi.Invoke(sapRfcDestination);
                IRfcTable detail2 = exportBapi.GetTable("DATA");

                string[] value;
                foreach (var item in detail2)
                {
                    value = item.GetString("WA").Replace(" ", "").Split(delimiter);
                    if (((string)value.GetValue(0)).Length != 10)
                    {
                        continue;
                    }
                    if ((string)value.GetValue(2) != "X")
                    {
                        continue;
                    }
                    if (((string)value.GetValue(1)).ToUpper() != warehouseCode.ToUpper())
                    {
                        continue;
                    }
                    location               = new Location();
                    location.Code          = (string)value.GetValue(0);
                    location.WarehouseCode = (string)value.GetValue(1);

                    //using (var db = new DbManager("HandHeldDB"))
                    //{
                    //    //insert new data
                    //    db.SetCommand(GetSql(88),
                    //    db.Parameter("@LocationCode", location.Code),
                    //    db.Parameter("@WarehouseCode", location.WarehouseCode),
                    //    db.Parameter("@isUse", location.IsUse)
                    //    ).ExecuteNonQuery();
                    //}

                    break;
                }
            }


            return(location);

            //List<SAPProxyII.ZLOCSTRC> locations;
            //string key = string.Format(LOCATION_ALL_KEY, DateTime.Now.Date.Day);
            //string keyOld = string.Format(LOCATION_ALL_KEY, DateTime.Now.AddDays(-1).Day);
            //object obj1 = _cacheManager.Get(keyOld);
            //object obj2 = _cacheManager.Get(key);

            //if (obj1 != null)
            //    _cacheManager.Remove(keyOld);

            //if (obj2 != null)
            //    locations = (List<SAPProxyII.ZLOCSTRC>)obj2;
            //else
            //{
            //    using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            //    {
            //        using (var prx = new SAPProxyII.UWProxy())
            //        {
            //            prx.Connection = sapConnection;

            //            SAPProxyII.ZLOCSTRCTable Tables = new SAPProxyII.ZLOCSTRCTable();
            //            prx.Zdd_Handheld_Get_Zlockstrc(ref Tables);

            //            locations = (List<SAPProxyII.ZLOCSTRC>)CollectionHelper.ConvertTo<SAPProxyII.ZLOCSTRC>(Tables.ToADODataTable());
            //            _cacheManager.Add(key, locations);
            //        }
            //    }
            //}

            //var location = locations.Find(p => p.Binloc == locationCode);
            //if (location != null)
            //{
            //    var locat = new Location();
            //    locat.Code = location.Binloc;
            //    locat.LocationType = location.Loctype;
            //    return locat;
            //}
            //else
            //    return null;
        }
Beispiel #18
0
        /// <summary>
        /// Below function gets products information.
        /// </summary>
        /// <param name="Productname"></param>
        /// <param name="RegionID"></param>
        /// <param name="RegionName"></param>
        /// <param name="LanguageId"></param>
        /// <param name="LanguageName"></param>
        /// <param name="Materialno"></param>
        /// <param name="MaxHitcount"></param>
        /// <param name="ViewType"></param>
        /// <returns></returns>
        public List <SIISAPMSDSDTO> GetProductsInformation(string RegionID, string RegionName, string LanguageId, string LanguageName, string Productname, string Materialno, int MaxHitcount, string ViewType)
        {
            List <SIISAPMSDSDTO> objMDSDSList = new List <SIISAPMSDSDTO>();
            var rfcDestination = RfcDestinationManager.GetDestination("SIISAP");

            try
            {
                if (rfcDestination != null)
                {
                    var getGateEntryRfc = rfcDestination.Repository.CreateFunction("ZEHS_MSDS_PRTL_F4_LIST_OF_MSDS");
                    /// PRODUCT
                    RfcStructureMetadata metaData      = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_PRODS");
                    IRfcStructure        structProduct = metaData.CreateStructure();
                    structProduct.SetValue("BRAND2", Productname);//, "ALKANOX® 240");
                    getGateEntryRfc.SetValue("I_PROD", structProduct);
                    /// REGION
                    RfcStructureMetadata metaDataCountry = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_CNTRY");
                    IRfcStructure        structRegions   = metaDataCountry.CreateStructure();
                    structRegions.SetValue("LDEPID", RegionID);    // "SDS_US");
                    structRegions.SetValue("LDEPNAM", RegionName); // "");
                    getGateEntryRfc.SetValue("I_REGION", structRegions);
                    // LANGUAGE
                    RfcStructureMetadata metaDataLanguage = rfcDestination.Repository.GetStructureMetadata("ZEHS_GEN_LNGS");
                    IRfcStructure        strucLanguage    = metaDataLanguage.CreateStructure();
                    strucLanguage.SetValue("SPRAS", LanguageId);   // "E");
                    strucLanguage.SetValue("SPTXT", LanguageName); // "");
                    getGateEntryRfc.SetValue("I_LANGUAGE", strucLanguage);
                    /// MATERIAL NUMBER
                    getGateEntryRfc.SetValue("I_MATNR", Materialno);          // "*");
                    /// MAX HIT COUNT
                    getGateEntryRfc.SetValue("I_MAX_HIT_COUNT", MaxHitcount); // 300);
                    /// I VIEW TYPE
                    getGateEntryRfc.SetValue("I_VIEWTYPE", ViewType);         // "");
                    // RfcSessionManager.BeginContext(rfcDestination);
                    getGateEntryRfc.Invoke(rfcDestination);
                    /// get the table values
                    IRfcTable Report       = getGateEntryRfc.GetTable("E_REPORT_TAB");
                    IRfcTable ObjectReport = getGateEntryRfc.GetTable("E_REPORT_OBJECT_TAB");
                    //Getting exported values from SAP
                    var COUNT       = getGateEntryRfc.GetValue("E_COUNT");
                    var MaxHITCount = getGateEntryRfc.GetValue("E_FLG_MAX_HIT_REACHED");
                    var objRTFT     = getGateEntryRfc.GetValue("E_BRAND2").ToString().Substring(getGateEntryRfc.GetValue("E_BRAND2").ToString().LastIndexOf("=") + 1).Replace("}", "");

                    RfcSessionManager.EndContext(rfcDestination);
                    foreach (var row in Report)
                    {
                        objMDSDSList.Add(new SIISAPMSDSDTO
                        {
                            ID           = row[0].ToString().Substring(row[0].ToString().IndexOf("=") + 1),
                            RECN         = row[1].ToString().Substring(row[1].ToString().IndexOf("=") + 1),
                            LANGU        = row[2].ToString().Substring(row[2].ToString().IndexOf("=") + 1),
                            LANGUTXT     = row[3].ToString().Substring(row[3].ToString().IndexOf("=") + 1),
                            LanguageID   = row[4].ToString().Substring(row[4].ToString().IndexOf("=") + 1),
                            LanguageText = row[5].ToString().Substring(row[5].ToString().IndexOf("=") + 1),
                            Version      = row[6].ToString().Substring(row[6].ToString().IndexOf("=") + 1),
                            REPTYPE      = row[7].ToString().Substring(row[7].ToString().IndexOf("=") + 1),
                            REPTYPETEXT  = row[8].ToString().Substring(row[8].ToString().IndexOf("=") + 1),
                            RVLID        = row[9].ToString().Substring(row[9].ToString().IndexOf("=") + 1),
                            RVLIDTXT     = row[10].ToString().Substring(row[10].ToString().IndexOf("=") + 1),
                            STATUS       = row[11].ToString().Substring(row[11].ToString().IndexOf("=") + 1),
                            STATUSTXT    = row[12].ToString().Substring(row[12].ToString().IndexOf("=") + 1),
                            GENDAT       = row[13].ToString().Substring(row[13].ToString().IndexOf("=") + 1),
                            VALDAT       = row[14].ToString().Substring(row[14].ToString().IndexOf("=") + 1),
                            REMARK       = row[15].ToString().Substring(row[15].ToString().IndexOf("=") + 1),
                            PrdFileName  = objRTFT
                        });
                        var listinfo = objMDSDSList;
                    }

                    rfcDestination = null;
                }
            }
            catch (Exception ex)
            {
                RfcSessionManager.EndContext(rfcDestination);
                rfcDestination = null;
                FilePath       = ConfigurationManager.AppSettings["siteUrl"];
                WriteLog(FilePath, ex.Message);
            }

            return(objMDSDSList);
        }
        public static RfcOutputListJson GetFunMetaList(string sysName, string funame)
        {
            RfcOutputListJson paralist = new RfcOutputListJson();

            try
            {
                if (string.IsNullOrEmpty(funame))
                {
                    throw new SAPException("请输入函数!!");
                }
                if (!SAPFunction.CheckFunction(sysName, funame))
                {
                    throw new SAPException("函数不存在!!");
                }
                funame = funame.ToUpper();
                RfcDestination destination = SAPDestination.GetDesByName(sysName);
                destination.Repository.ClearAllMetadata();
                RfcFunctionMetadata MetaData = destination.Repository.GetFunctionMetadata(funame);
                IRfcFunction        function = null;
                function = MetaData.CreateFunction();
                //根据参数的方向,分为四种(CHANGING,EXPORT,IMPORT,TABLES);
                for (int i = 0; i < MetaData.ParameterCount; i++)
                {
                    RfcParameterMetadata pMetadata = MetaData[i];
                    paralist.All.Add(pMetadata);
                    switch (pMetadata.Direction)
                    {
                    case RfcDirection.CHANGING:
                        paralist.Change.Add(pMetadata);
                        break;

                    case RfcDirection.EXPORT:
                        paralist.Export.Add(pMetadata);
                        break;

                    case RfcDirection.IMPORT:
                        paralist.Import.Add(pMetadata);
                        break;

                    case RfcDirection.TABLES:
                        paralist.Tables.Add(pMetadata);
                        break;
                    }
                    //参数也可能是结构体,表,ABAP对象
                    //一定要分开TRY,因为有些是没有的
                    if (pMetadata.DataType == RfcDataType.STRUCTURE)
                    {
                        try
                        {
                            //结构体的行项目结构
                            List <object>        elelist   = new List <object>();
                            RfcStructureMetadata strucmeta = pMetadata.ValueMetadataAsStructureMetadata;
                            for (int f = 0; f < strucmeta.FieldCount; f++)
                            {
                                RfcFieldMetadata fieldm = strucmeta[f];
                                elelist.Add(fieldm);
                            }
                            paralist.Objects.Add(pMetadata.Name, elelist);
                        }
                        catch (Exception)
                        {
                            //  throw new SAPException(ee.Message);
                        }
                    }
                    if (pMetadata.DataType == RfcDataType.TABLE)
                    {
                        //表结构的行项目结构
                        List <object>    tbllist = new List <object>();
                        RfcTableMetadata tablem  = pMetadata.ValueMetadataAsTableMetadata;
                        for (int t = 0; t < tablem.LineType.FieldCount; t++)
                        {
                            RfcFieldMetadata fieldm = tablem.LineType[t];
                            tbllist.Add(fieldm);
                        }
                        paralist.Objects.Add(pMetadata.Name, tbllist);
                    }
                    if (pMetadata.DataType == RfcDataType.CLASS)
                    {
                        //abap object 属性
                        List <object>         attlist  = new List <object>();
                        RfcAbapObjectMetadata abapitem = pMetadata.ValueMetadataAsAbapObjectMetadata;
                        for (int o = 0; o < abapitem.AttributeCount; o++)
                        {
                            RfcAttributeMetadata abapobject = abapitem[o];
                            attlist.Add(abapobject);
                        }
                        paralist.Objects.Add(pMetadata.Name, attlist);
                    }
                }
                return(paralist);
            }
            catch (Exception ee)
            {
                throw new SAPException(ee.Message);
            }
        }