public ServerResult UpdateInstance(string jsonData)
        {
            ServerResult result = new ServerResult();

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

                DEInstanceAdapter.Instance.Update(resultInstance);

                result.Result = string.Format("{{'ID':'{0}'}}", resultInstance.ID);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Result    = string.Format("{{'ErrorMsg':'{0}'}}", e.Message);
            }

            return(result);
        }
        public ServerResult GetExistInstance(string instanceID)
        {
            ServerResult result = new ServerResult();

            try
            {
                instanceID.CheckStringIsNullOrEmpty <ArgumentNullException>("实例ID不能为空");

                //根据实例ID获取实例对象
                DEEntityInstanceBase instance = DEInstanceAdapter.Instance.Load(instanceID);

                string json = JSONSerializerExecute.Serialize(instance);

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

            return(result);
        }
        public ServerResult GetInstanceList(string entityCodeName, int pageIndex, int pageSize, ref int totalNum)
        {
            ServerResult result = new ServerResult();

            try
            {
                entityCodeName.CheckStringIsNullOrEmpty <ArgumentNullException>("实体定义CodeName不能为空");
                DynamicEntity entity = DEDynamicEntityAdapter.Instance.LoadByCodeName(entityCodeName) as DynamicEntity;

                //根据实例ID获取实例对象
                DEEntityInstanceBaseCollection instances = DEInstanceAdapter.Instance.LoadByEntityID(entity.ID, pageIndex, pageSize, ref totalNum);

                string json = JSONSerializerExecute.Serialize(instances);

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

            return(result);
        }
        public ServerResult GetNewInstance(string codeName, DateTime timeStamp)
        {
            ServerResult result = new ServerResult();

            try
            {
                codeName.CheckStringIsNullOrEmpty <ArgumentNullException>("CodeName不能为空");
                timeStamp.NullCheck <ArgumentNullException>("时间戳不能为NULL");

                var entnity = DEDynamicEntityAdapter.Instance.LoadByCodeName(codeName, timeStamp) as DynamicEntity;
                DEEntityInstanceBase instance = entnity.CreateInstance();

                string json = JSONSerializerExecute.Serialize(instance);

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

            return(result);
        }
        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);
        }