Example #1
0
        private static void AddTypeElements(ODMLDocument doc, IList<EntityType> typeList)
        {
            int row = 0, column = 0;
            for (int i = 0, c = typeList.Count; i < c; i++)
            {
                var type = typeList[i];

                var typeFullName = type.FullName;
                //如果这个实体还没有加进来,就创建一个元素并加入到列表中。
                if (doc.EntityTypes.All(e => e.FullName != typeFullName))
                {
                    var entityTypeEl = new EntityTypeElement(typeFullName);
                    entityTypeEl.FullName = typeFullName;
                    entityTypeEl.Left = column * 300;
                    entityTypeEl.Top = row * 200;
                    entityTypeEl.IsAggtRoot = type.IsAggtRoot;
                    entityTypeEl.HideProperties = true;
                    entityTypeEl.Label = GetDomainName(type);

                    foreach (var vp in type.ValueProperties)
                    {
                        var propertyEl = new PropertyElement(vp.Name);
                        propertyEl.Label = GetDomainName(vp);

                        if (vp.PropertyType == ValuePropertyType.Enum)
                        {
                            propertyEl.PropertyType = vp.EnumType.Name;
                        }
                        else
                        {
                            propertyEl.PropertyType = vp.PropertyType.ToString();
                        }

                        //可空类型,显示在属性上时,需要添加"?" 号。
                        if (vp.Nullable)
                        {
                            propertyEl.PropertyType += "?";
                        }

                        entityTypeEl.Properties.Add(propertyEl);
                    }

                    doc.EntityTypes.Add(entityTypeEl);

                    column++;
                    //一排四个。
                    if (column == 3)
                    {
                        row++;
                        column = 0;
                    }
                }
            }
        }
Example #2
0
        private EntityTypeControl CreateEntityTypeControl(EntityTypeElement type)
        {
            var control = new EntityTypeControl();
            control.DataContext = type;

            BindBlockControl(control);
            SetBinding(control, EntityTypeControl.HideDetailsProperty, "HideProperties");
            SetBinding(control, EntityTypeControl.IsAggtRootProperty, "IsAggtRoot");

            CreateProperties(control, type.Properties);
            type.Properties.CollectionChanged += (o, e) =>
            {
                var oldItems = e.OldItems ?? type.Properties.PopClearedItems();
                if (oldItems != null)
                {
                    foreach (PropertyElement oldItem in oldItems)
                    {
                        var property = control.Items.First(i => i.DataContext == oldItem);
                        control.Items.Remove(property);
                    }
                }
                if (e.NewItems != null)
                {
                    CreateProperties(control, e.NewItems);
                }
            };

            return control;
        }