Exemple #1
0
        /// <summary>
        /// 删除实体跟外部结构关联
        /// </summary>
        /// <param name="entity"></param>
        public void DeleteEntityMapping(DynamicEntity entity, OuterEntity oEntity)
        {
            var relation = entity.AllMembersRelations.Where(p => p.ID == oEntity.ID).FirstOrDefault();

            if (relation != null)
            {
                //删除实体与外部结构关系
                DEMemberRelationAdapter.Instance.UpdateStatus(relation, SchemaObjectStatus.Deleted);
            }


            //删除实体字段和外部字段的关系
            oEntity.Fields.ForEach(f =>
            {
                var fRelation = f.AllMemberOfRelations.Where(rl => entity.Fields.Any(fd => fd.ID == rl.ContainerID)).FirstOrDefault();

                if (fRelation != null)
                {
                    DEMemberRelationAdapter.Instance.UpdateStatus(fRelation, SchemaObjectStatus.Deleted);
                }

                //删除外部字段
                DESchemaObjectAdapter.Instance.UpdateStatus(f, SchemaObjectStatus.Deleted);
            });

            //删除外部实体
            DESchemaObjectAdapter.Instance.UpdateStatus(oEntity, SchemaObjectStatus.Deleted);
        }
Exemple #2
0
        /// <summary>
        /// 创建外部实体
        /// </summary>
        /// <returns></returns>
        private OuterEntity createOuterEntity(string flag = "new")
        {
            var outerEntity = new OuterEntity()
            {
                ID          = Guid.NewGuid().ToString(),
                Name        = "外部实体",
                Description = "描述" + flag,
                //CodeName = "OuterEntity",
                Creator = (IUser)OguBase.CreateWrapperObject(new OguUser("22c3b351-a713-49f2-8f06-6b888a280fff")),//wangli5
                SortNo  = 0
            };

            return(outerEntity);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            EntityMapping mapping = new EntityMapping();

            if (!TimePointContext.Current.UseCurrentTime)
            {
                this.okButton.Visible       = false;
                txt_OuterEntityName.Enabled = false;
                ddl_InType.Enabled          = false;
                grid.ReadOnly = true;
            }
            if (!IsPostBack)
            {
                ExceptionHelper.TrueThrow(string.IsNullOrEmpty(Request.QueryString["EntityID"]), "EntityID不能为空");

                DynamicEntity innerEntity = DESchemaObjectAdapter.Instance.Load(Request.QueryString["EntityID"].Trim()) as DynamicEntity;
                mapping.InnerEntity = innerEntity;

                OuterEntity outerEntity = new OuterEntity();
                outerEntity.ID = Guid.NewGuid().ToString();

                mapping.OuterEntityID = outerEntity.ID;
                //外部实体
                if (Request.QueryString["OuterEntityID"].IsNotEmpty())
                {
                    outerEntity = DESchemaObjectAdapter.Instance.Load(Request.QueryString["OuterEntityID"].Trim()) as OuterEntity;

                    mapping.OuterEntityID = outerEntity.ID;

                    mapping.OuterEntityName = outerEntity.Name;

                    mapping.OuterEntityInType = outerEntity.CustomType;
                }

                //绑定下拉框
                this.ddl_InType.BindData(EnumItemDescriptionAttribute.GetDescriptionList(typeof(InType)), "EnumValue", "Description");
            }

            this.bindingControl.Data = mapping;
        }
        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);
        }
Exemple #6
0
        public void CopyEntityWithOutEntityMethodTest()
        {
            // /集团公司/管道板块/运输
            string categoryID = "48BE753C-630D-42F4-A02D-D2B50818F817";
            // /集团公司/销售板块/销售订单
            string terminalCategoryID = "EBABB15A-AFD8-4072-A5C9-03F1B0B5CDFF";

            var entity      = creatEntity(categoryID);
            var childEntity = creatChildEntity(categoryID);
            //外部实体字段
            OuterEntityField outField = new OuterEntityField()
            {
                Name        = "OutField",
                ID          = Guid.NewGuid().ToString(),
                Description = "外部字段"
            };
            //外部实体
            OuterEntity outEntity = new OuterEntity()
            {
                ID          = Guid.NewGuid().ToString(),
                Name        = "OEntity",
                Description = "外部实体"
            };


            //子表入库
            DEObjectOperations.InstanceWithoutPermissions.AddEntity(childEntity);
            //子表CodeName
            string childCodeName = childEntity.CodeName;
            //主表字段跟子表关联
            var field = entity.Fields[0];

            field.FieldType = FieldTypeEnum.Collection;
            field.ReferenceEntityCodeName = childCodeName;
            // field.OuterEntityFields.Add(outField);
            //主表入库
            DEObjectOperations.InstanceWithoutPermissions.AddEntity(entity);

            //实体字段与外部实体字段的Mapping
            EntityFieldMapping fieldMapping = new EntityFieldMapping()
            {
                FieldID           = field.ID,
                FieldDefaultValue = field.DefaultValue,
                FieldDesc         = field.Description,
                FieldLength       = field.Length,
                FieldName         = field.Name,
                FieldTypeName     = field.FieldType.ToString(),
                //OuterFieldID = outField.ID,
                //OuterFieldName = outField.Name,
                SortNo = field.SortNo
            };
            List <EntityFieldMapping> entityFieldMappingCollection = new List <EntityFieldMapping>();

            entityFieldMappingCollection.Add(fieldMapping);
            //实体和外部实体的Mapping
            EntityMapping mapping = new EntityMapping()
            {
                InnerEntity                  = entity,
                OuterEntityID                = outEntity.ID,
                OuterEntityName              = outEntity.Name,
                OuterEntityInType            = Contract.InType.StandardInterface,
                EntityFieldMappingCollection = entityFieldMappingCollection
            };

            DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(mapping);

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

            entitiesIDs.Add(entity.ID);
            entitiesIDs.Add(childEntity.ID);
            List <string> categoriesIDs = new List <string>();

            categoriesIDs.Add(terminalCategoryID);
            DEObjectOperations.InstanceWithoutPermissions.CopyEntities(entitiesIDs, categoriesIDs);

            DynamicEntity copyEntity      = DEDynamicEntityAdapter.Instance.LoadByCodeName("/集团公司/销售板块/销售订单/" + entity.Name) as DynamicEntity;
            DynamicEntity copyChildEntity = DEDynamicEntityAdapter.Instance.LoadByCodeName("/集团公司/销售板块/销售订单/" + childEntity.Name) as DynamicEntity;

            Assert.IsNotNull(copyEntity, string.Format("实体[/集团公司/销售板块/销售订单/{0}]复制失败", entity.Name));
            Assert.IsNotNull(copyChildEntity, string.Format("子实体[/集团公司/销售板块/销售订单/{0}]复制失败", childEntity.Name));
            Assert.AreEqual(copyEntity.Fields[0].FieldType, FieldTypeEnum.Collection, string.Format("实体[/集团公司/销售板块/销售订单/{0}]的字段复制失败", entity.Name));
            Assert.AreEqual(copyEntity.Fields[0].ReferenceEntityCodeName, copyChildEntity.CodeName, string.Format("实体[/集团公司/销售板块/销售订单/{0}]的字段复制失败", entity.Name));
            //Assert.AreEqual(copyEntity.OuterEntities.Count, entity.OuterEntities.Count, "实体字段外部实体复制失败");
            //Assert.AreEqual(copyEntity.OuterEntities[0].Name, entity.OuterEntities[0].Name, "实体字段外部实体复制失败");
            //Assert.AreEqual(copyEntity.Fields[0].OuterEntityFields.Count, 1, "实体字段外部实体字段复制失败");
            //Assert.AreEqual(copyEntity.Fields[0].OuterEntityFields.Count, entity.Fields[0].OuterEntityFields.Count, "实体字段外部实体字段复制失败");
            //Assert.AreEqual(copyEntity.Fields[0].OuterEntityFields[0].Name, "OutField", "实体字段外部实体字段复制失败");
        }