Ejemplo n.º 1
0
        //获取RFC结构
        protected void btn_GenerateEntityByRFC_Click(object sender, EventArgs e)
        {
            var srv = new Saplocalhost.WebServiceConnectSAPSoapClient();

            //SAPLoginParams Params = SAPLoginParams.GetConfig();
            //SAPClient sapInstance =
            //    SAPClientAdapter.Instance.LoadByID(ConfigurationManager.AppSettings["SAPInstanceId"].Trim());
            //SAPClient sapInstance = SAPClientAdapter.Instance.LoadByID(this.hidSAPInstanceId.Value.Trim());

            //var param = new Saplocalhost.SAPPara()
            //{
            //    ApplicationServer = sapInstance.ApplicationServer,
            //    Client = sapInstance.Client,
            //    Language = sapInstance.Language,
            //    Password = sapInstance.Password,
            //    SystemNumber = int.Parse(sapInstance.SystemNumber),
            //    User = sapInstance.User,
            //    MessageServerHost = sapInstance.MessageServerHost,
            //    MessageServerService = sapInstance.MessageServerService,
            //    LogonGroup = sapInstance.LogonGroup,
            //    AppServerService = sapInstance.AppServerService,
            //    SystemID = sapInstance.SystemID
            //};

            //DataTable table = srv.SAP_RFCParams_Get(txt_TCode.Text.Trim(), param);

            //RecordResultCollection collection = ConvertTableToRecordResult(table);
            //BindData(collection);
        }
Ejemplo n.º 2
0
        public RecordResultCollection GetData(string tCode)
        {
            var       srv   = new Saplocalhost.WebServiceConnectSAPSoapClient();
            DataTable table = srv.GetEntityDefine(tCode);

            return(ConvertTableToRecordResult(table));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public ETLSapTableResultCollection GetData(string sapTableName)
        {
            using (var srv = new Saplocalhost.WebServiceConnectSAPSoapClient())
            {
                // 新的取得SAP连接信息
                string sapInstanceId = this.hidSAPInstanceId.Value;
                sapInstanceId.CheckStringIsNullOrEmpty("sapInstanceId");
                SAPClient Params = SAPClientAdapter.Instance.LoadByID(sapInstanceId);

                Saplocalhost.SAPPara param = new Saplocalhost.SAPPara()
                {
                    ApplicationServer = Params.ApplicationServer,
                    Client            = Params.Client,
                    Language          = Params.Language,
                    Password          = Params.Password,
                    SystemNumber      = int.Parse(Params.SystemNumber),
                    User                 = Params.User,
                    AppServerService     = Params.AppServerService,
                    LogonGroup           = Params.LogonGroup,
                    MessageServerHost    = Params.MessageServerHost,
                    MessageServerService = Params.MessageServerService,
                    SystemID             = Params.SystemID
                };

                DataTable table = srv.SAP_TableFiled_Get(sapTableName, param);

                return(GetDatas(table));
            }
        }
        public RecordResultCollection GetData(string tCode)
        {
            //Saplocalhost.WebServiceConnectSAP srv = new Saplocalhost.WebServiceConnectSAP();
            var       srv   = new Saplocalhost.WebServiceConnectSAPSoapClient();
            DataTable table = srv.GetEntityDefine(tCode);
            RecordResultCollection resultList = new RecordResultCollection();

            var parentRows = table.Select();
            int sortNumber = 0;

            foreach (var item in parentRows)
            {
                sortNumber++;
                RecordResult result = new RecordResult();
                result.SortNo        = sortNumber;
                result.EntityName    = Convert.ToString(item["实体名"]);
                result.EntityDesc    = Convert.ToString(item["实体描述"]);
                result.DefaultValue  = Convert.ToString(item["默认值"]);
                result.IsMasterTable = Convert.ToString(item["主子标识"]) == "主" ? true : false;
                result.FieldName     = Convert.ToString(item["字段名"]);
                FieldTypeEnum type = new FieldTypeEnum();
                switch (Convert.ToString(item["字段类型"]).ToLower())
                {
                case "string":
                    type = FieldTypeEnum.String;
                    break;

                case "int":
                    type = FieldTypeEnum.Int;
                    break;

                case "bool":
                    type = FieldTypeEnum.Bool;
                    break;

                case "datetime":
                    type = FieldTypeEnum.DateTime;
                    break;

                case "decimal":
                    type = FieldTypeEnum.Decimal;
                    break;
                }
                result.FieldType = type;

                result.FieldDesc = Convert.ToString(item["字段描述"]);

                result.FieldLength = int.Parse(Convert.ToString(item["字段长度"]));

                resultList.Add(result);
            }
            return(resultList);
        }
        public ServerResult ExecuteSAPRFC(string rfcName, string jsonData, string SAPInstanceId)
        {
            ServerResult result = new ServerResult();

            try
            {
                //反序列化
                DEEntityInstanceBase resultInstance = JSONSerializerExecute.Deserialize <DEEntityInstanceBase>(jsonData);

                //调用sap服务
                #region
                if (string.IsNullOrEmpty(SAPInstanceId))
                {
                    throw new Exception("请检查Config文件中是否配置了SAPInstanceId");
                }

                //todo:目前实体跟sap结构是1对1 所以只取第一个外部实体,将来会改成一对多,需要调用方传入外部实体名
                OuterEntity outerEntity = resultInstance.EntityDefine.OuterEntities.FirstOrDefault();
                outerEntity.NullCheck(string.Format("找不到实体定义【{0}】的外部实体!", resultInstance.EntityDefine.CodeName));

                string          tCode  = outerEntity.Name;
                List <SapValue> values = resultInstance.ToParams(tCode);

                //sap服务定义
                //Saplocalhost.WebServiceConnectSAP sapService = new Saplocalhost.WebServiceConnectSAP();
                var sapService = new Saplocalhost.WebServiceConnectSAPSoapClient();
                Saplocalhost.InstanceParam sappar = new Saplocalhost.InstanceParam();

                #region 给sap参数赋值

                //todo:这的转换不太好,以后WebService改为WCF后会解决此问题
                sappar.SapType = outerEntity.CustomType == InType.CustomInterface ? Saplocalhost.InType.CustomInterface : Saplocalhost.InType.StandardInterface;
                sappar.Values  = ChangeToWSValueType(values);

                //获取Sap用户信息
                string errorMessage = string.Empty;

                // 获取SAP用户连接信息
                SAPClient sapParamLoad = SAPClientAdapter.Instance.LoadByID(SAPInstanceId);

                if (sapParamLoad == null)
                {
                    errorMessage = "请检查Config文件的SAPInstanceId的配置项";
                }
                //if (string.IsNullOrEmpty(sapParamLoad.ApplicationServer) || string.IsNullOrEmpty(sapParamLoad.SystemNumber)
                //     || string.IsNullOrEmpty(sapParamLoad.Client) || string.IsNullOrEmpty(sapParamLoad.User)
                //     || string.IsNullOrEmpty(sapParamLoad.Password) || string.IsNullOrEmpty(sapParamLoad.Language))
                //{
                //    errorMessage = "请检查SAP连接数据";
                //}
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    throw new Exception(errorMessage);
                }

                #endregion

                //构造SAP登录参数
                var sapParam = buildSapLogonParam(sapParamLoad);

                //返回值
                string resultSap = string.Empty;
                Saplocalhost.InstanceParam returnValue = sapService.ExecuteSAPRFC(rfcName, sappar, sapParam);

                resultInstance.FromParams(ChangeToSapValue(returnValue.Values.ToArray()));
                //将返回结果序列化之后return给上一层(解决WS传输问题)
                result.ObjResult = JSONSerializerExecute.Serialize(resultInstance);
                #endregion
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Result    = string.Format("{{'ErrorMsg':'{0}'}}", e.Message);
            }

            return(result);
        }
        public ServerResult ExecuteSAPBDC(string jsonData, string clientID)
        {
            ServerResult result    = new ServerResult();
            string       resultSap = string.Empty;

            try
            {
                //反序列化
                DEEntityInstanceBase resultInstance = JSONSerializerExecute.Deserialize <DEEntityInstanceBase>(jsonData);

                DEInstanceAdapter.Instance.Update(resultInstance);

                //调用sap服务
                #region

                //todo:目前实体跟sap结构是1对1 所以只取第一个外部实体,将来会改成一对多,需要调用方传入外部实体名
                OuterEntity outerEntity = resultInstance.EntityDefine.OuterEntities.FirstOrDefault();
                outerEntity.NullCheck(string.Format("找不到实体定义【{0}】的外部实体!", resultInstance.EntityDefine.CodeName));

                string          tCode  = outerEntity.Name;
                List <SapValue> values = resultInstance.ToParams(tCode);

                //sap服务定义
                Saplocalhost.WebServiceConnectSAPSoapClient sapService = new Saplocalhost.WebServiceConnectSAPSoapClient();
                Saplocalhost.InstanceParam sappar = new Saplocalhost.InstanceParam();

                #region 给sap参数赋值
                //todo:这的转换不太好,以后WebService改为WCF后会解决此问题
                sappar.SapType = outerEntity.CustomType == InType.CustomInterface ? Saplocalhost.InType.CustomInterface : Saplocalhost.InType.StandardInterface;
                sappar.Values  = GetRealSapValues(values);

                //SAPLoginParams Params = SAPLoginParams.GetConfig();

                string errorMessage = string.Empty;

                // 获取SAP用户连接信息
                SAPClient sapParamLoad = SAPClientAdapter.Instance.LoadByID(clientID);

                if (sapParamLoad == null)
                {
                    errorMessage = "请检查Config文件的SapAppServer和SapClient配置项";
                }
                if (string.IsNullOrEmpty(sapParamLoad.ApplicationServer) || string.IsNullOrEmpty(sapParamLoad.Client))
                {
                    errorMessage = "请检查Config文件的SapAppServer和SapClient配置项";
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    throw new Exception(errorMessage);
                }

                #endregion

                var sapParam = buildSapLogonParam(sapParamLoad);

                //返回值
                //(问海军)
                DataTable returnResult = sapService.ExecuteSAP(out resultSap, tCode, sappar, sapParam);
                returnResult.TableName = "sapResult";
                result.ObjResult       = SerializeDataTableXml(returnResult);

                #endregion
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Result    = e.Message;
            }

            return(result);
        }