Beispiel #1
0
        private UserControls.ListControls.Item AddNewListItem(object item, System.Collections.IList list, UserControls.ListControls.GroupCard rootFieldGroupCard, string fieldName)
        {
            var listControlItem = new UserControls.ListControls.Item();

            var ProcessedClass = ProcessClass(item);

            ProcessedClass.ForEach(control =>
            {
                listControlItem.ControlWrapPanel.Children.Add(control);
            });

            listControlItem.DeleteItemIcon.MouseLeftButtonUp += (s, e) =>
            {
                var deleteItemMessageBox = new Windows.AFG_MessageBox("Remove Item?", "Are you sure you want to remove this?");
                deleteItemMessageBox.ShowDialog();
                if (deleteItemMessageBox.MessageBoxResult == MessageBoxResult.Yes)
                {
                    rootFieldGroupCard.ControlsWrapPanel.Children.Remove(listControlItem);
                    list.Remove(item);
                    OnPropertyModified?.Invoke(fieldName, null);
                }
            };

            return(listControlItem);
        }
Beispiel #2
0
        private UserControls.ListControls.Item AddNewItemListItem(FormControlSettings controlSettings, UserControls.ListControls.GroupCard rootFieldGroupCard, System.Collections.IList list, string fieldName)
        {
            var userControl = HandleUserControl(controlSettings);

            if (userControl != null)
            {
                var listControlItem = new UserControls.ListControls.Item();
                listControlItem.ControlWrapPanel.Children.Add(userControl);

                listControlItem.DeleteItemIcon.MouseLeftButtonUp += (s, e) =>
                {
                    var deleteItemMessageBox = new Windows.AFG_MessageBox("Remove Item?", "Are you sure you want to remove this?");
                    deleteItemMessageBox.ShowDialog();
                    if (deleteItemMessageBox.MessageBoxResult == MessageBoxResult.Yes)
                    {
                        rootFieldGroupCard.ControlsWrapPanel.Children.Remove(listControlItem);
                        list.Remove(controlSettings.Value);
                        OnPropertyModified?.Invoke(fieldName, null);
                    }
                };

                return(listControlItem);
            }

            return(null);
        }
Beispiel #3
0
        private IEnumerable <UserControl> HandleNestedList(object rootClass)
        {
            var rootClassType = rootClass.GetType();

            var nestedLists = Helpers.GetProperties(rootClassType, Types.NestedList);
            var normalItems = Helpers.GetProperties(rootClassType, Types.Prop);

            normalItems.ForEach(info =>
            {
                if (info.PropertyType.IsGenericType && info.PropertyType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    nestedLists.Add(info);
                }
            });

            var userControls = new List <UserControl>();

            nestedLists.ForEach(propInfo =>
            {
                var formField = (FormField)propInfo.GetCustomAttributes(typeof(FormField), true).FirstOrDefault();

                var rootFieldGroupCard = new UserControls.ListControls.GroupCard();

                var list = (System.Collections.IList)propInfo.GetValue(rootClass, null);

                var listType = propInfo.PropertyType.GetGenericArguments()[0];
                if (formField.NestedListClassType != null)
                {
                    listType = formField.NestedListClassType;
                }

                if (list == null)
                {
                    var constructedListType = typeof(List <>).MakeGenericType(listType);

                    list = Activator.CreateInstance(constructedListType) as System.Collections.IList;
                }

                var displayName = propInfo.Name;

                var fieldName = rootClassType.FullName + "." + propInfo.Name;

                if (formField.DisplayName != string.Empty)
                {
                    displayName = formField.DisplayName;
                }

                rootFieldGroupCard.AddItemIcon.MouseLeftButtonUp += (s, e) =>
                {
                    var nestedItem = Activator.CreateInstance(listType);

                    list.Add(nestedItem);

                    OnPropertyModified?.Invoke(fieldName, nestedItem);

                    var addNewItem = AddNewListItem(nestedItem, list, rootFieldGroupCard, fieldName);

                    rootFieldGroupCard.ControlsWrapPanel.Children.Add(addNewItem);
                };

                rootFieldGroupCard.DisplayNameTextBlock.Text = displayName;

                foreach (var item in list)
                {
                    var addNewItem = AddNewListItem(item, list, rootFieldGroupCard, fieldName);
                    rootFieldGroupCard.ControlsWrapPanel.Children.Add(addNewItem);
                }
                userControls.Add(rootFieldGroupCard);
            });

            return(userControls);
        }
Beispiel #4
0
        private IEnumerable <UserControl> HandleItemList(object rootClass)
        {
            var rootClassType = rootClass.GetType();
            var userControls  = new List <UserControl>();

            var normalItems = Helpers.GetProperties(rootClassType, Types.ItemList);

            foreach (var info in normalItems)
            {
                var formField = (FormField)info.GetCustomAttributes(typeof(FormField), true).FirstOrDefault();
                if (formField == null)
                {
                    continue;
                }

                var rootFieldGroupCard = new UserControls.ListControls.GroupCard();

                var list      = (System.Collections.IList)info.GetValue(rootClass, null);
                var listType  = info.PropertyType.GetGenericArguments()[0];
                var fieldName = rootClassType.FullName + "." + info.Name;

                var objectType = formField.ObjectTypeName;
                if (formField.ObjectTypeName == ObjectTypes.Default)
                {
                    if (!Enum.IsDefined(typeof(ObjectTypes), listType.Name))
                    {
                        continue;
                    }

                    objectType = (ObjectTypes)Enum.Parse(typeof(ObjectTypes), listType.Name);
                }

                var displayNameWidth = 50;

                if ((formField.DisplayName.Length * 10) > displayNameWidth)
                {
                    displayNameWidth = (formField.DisplayName.Length * 10);
                }

                foreach (var o in list)
                {
                    var formControlSettings = new FormControlSettings
                    {
                        DisplayNameWidth = displayNameWidth,
                        ClassType        = rootClassType,
                        FieldName        = "Item",
                        ObjectType       = objectType,
                        FormField        = formField,
                        Value            = o
                    };

                    var controlItem = AddNewItemListItem(formControlSettings, rootFieldGroupCard, list, fieldName);
                    if (controlItem != null)
                    {
                        rootFieldGroupCard.ControlsWrapPanel.Children.Add(controlItem);
                    }
                }

                rootFieldGroupCard.AddItemIcon.MouseLeftButtonUp += (s, e) =>
                {
                    var formControlSettings = new FormControlSettings
                    {
                        DisplayNameWidth = displayNameWidth,
                        ClassType        = rootClassType,
                        FieldName        = "Item",
                        ObjectType       = objectType,
                        FormField        = formField,
                        Value            = ""
                    };

                    var controlItem = AddNewItemListItem(formControlSettings, rootFieldGroupCard, list, fieldName);
                    if (controlItem != null)
                    {
                        rootFieldGroupCard.ControlsWrapPanel.Children.Add(controlItem);
                    }
                };


                var displayName = info.Name;
                if (formField.DisplayName != string.Empty)
                {
                    displayName = formField.DisplayName;
                }
                rootFieldGroupCard.DisplayNameTextBlock.Text = displayName;

                userControls.Add(rootFieldGroupCard);
            }

            return(userControls);
        }