Пример #1
0
        internal Dictionary <string, PreBindingArgs> ApplyMapping(FieldInfo[] target, BindingConfigurator FTypeToControlMapping = null)
        {
            Dictionary <string, PreBindingArgs> map = new Dictionary <string, PreBindingArgs>();

            foreach (FieldInfo finfo in target)
            {
                PreBindingArgs args = new PreBindingArgs
                {
                    TargetVariable_Type      = finfo.FieldType,
                    TargetVariable_Name      = finfo.Name,
                    TargetVariable_FieldInfo = finfo,
                    FieldSet_Name            = finfo.Name,
                    FieldSet_FieldType       = null,
                    FieldSet_FieldFlags      = FieldFlags.None,
                    DoBind = true,
                    Post   = null,
                };
                if (!map.ContainsKey(finfo.Name))
                {
                    map.Add(finfo.Name, args);
                }
            }
            FTypeToControlMapping?.Invoke(ref map);
            return(map);
        }
Пример #2
0
        internal Dictionary <string, PreBindingArgs> ResolveTypes(Dictionary <string, PreBindingArgs> map)
        {
            int _i     = 0;
            var keyArr = new string[map.Keys.Count];

            foreach (string str in map.Keys)
            {
                keyArr[_i] = str;
                _i++;
            }
            for (int i = 0; i < keyArr.Length; i++)
            {
                string         str         = keyArr[i];
                PreBindingArgs bindingArgs = map[str];
                if (!bindingArgs.DoBind)
                {
                    continue;
                }

                if (bindingArgs.FieldSet_FieldType is null)
                {
                    bindingArgs.FieldSet_FieldType = DefaultControlMapping(bindingArgs.TargetVariable_Type);
                }

                if (bindingArgs.FieldSet_FieldType == typeof(ComboBox))
                {
                    Owner.Modify.AddField <ComboBox>(bindingArgs.FieldSet_Name, bindingArgs.FieldSet_FieldFlags);
                    ComboBox comboBox = Owner.Modify.EditField() as ComboBox;
                    comboBox.DataSource    = Enum.GetValues(bindingArgs.TargetVariable_Type);
                    comboBox.SelectedIndex = -1;
                    comboBox.SelectedItem  = null;
                    //Owner.Binder.BindToVariable(null, bindingArgs.TargetVariable_Name);
                    continue;
                }

                if (bindingArgs.TargetVariable_Type.IsClass)
                {
                    int gsize = 0;
                    foreach (FieldInfo innerInfo in bindingArgs.TargetVariable_Type.GetFields())
                    {
                        foreach (string innerStr in map.Keys)
                        {
                            if (innerInfo.Name.Equals(innerStr))
                            {
                                gsize++;
                            }
                        }
                    }
                    if (gsize > 0)
                    {
                        bindingArgs.IsGroup   = true;
                        bindingArgs.GroupSize = gsize;
                        map[str] = new PreBindingArgs(bindingArgs);
                    }
                }
                Owner.Modify.AddField(bindingArgs.FieldSet_FieldType, bindingArgs.FieldSet_Name, bindingArgs.FieldSet_FieldFlags);
            }

            return(map);
        }
Пример #3
0
        internal void DoBind(Dictionary <string, PreBindingArgs> map)
        {
            int _i     = 0;
            var keyArr = new string[map.Keys.Count];

            foreach (string str in map.Keys)
            {
                keyArr[_i] = str;
                _i++;
            }
            for (int i = 0; i < keyArr.Length; i++)
            {
                string         str         = keyArr[i];
                PreBindingArgs bindingArgs = map[str];
                Fieldset       fieldset    = Provider.Request <FieldLocatorService>().LocateName(bindingArgs.FieldSet_Name);

                if (bindingArgs.IsGroup)
                {
                    Type localType = bindingArgs.TargetVariable_Type;
                    for (int j = 1; j <= bindingArgs.GroupSize; j++)
                    {
                        var fs = Owner.LocateField.LocateName(map[keyArr[i + j]].FieldSet_Name);
                        for (int k = 0; k < fieldset.GroupFieldInfo.Count; k++)
                        {
                            fs.GroupFieldInfo.Add(fieldset.GroupFieldInfo[k]);
                        }

                        fs.GroupFieldInfo.Add(bindingArgs.TargetVariable_FieldInfo);

                        Owner.Binder.BindToVariable(map[keyArr[i + j]].FieldSet_Name, map[keyArr[i + j]].TargetVariable_Name);

                        // Fix posX of fields/labels
                        var offX = (fs.GroupFieldInfo.Count * 10);
                        fs.BackPanel.Location = new Point(fs.BackPanel.Location.X + offX, fs.BackPanel.Location.Y);
                        fs.BackPanel.Width   -= offX;
                        fs.Field.Location     = new Point(fs.Field.Location.X - offX, fs.Field.Location.Y);
                    }

                    continue;
                }
                else
                {
                    Owner.Binder.BindToVariable(bindingArgs.FieldSet_Name, bindingArgs.TargetVariable_Name);
                }

                if (fieldset.Field  is ComboBox cb)
                {
                    cb.SelectedIndex = -1;
                }

                bindingArgs.Post?.Invoke(Owner.LocateField.LocateLast());
            }
        }
Пример #4
0
 public PreBindingArgs(PreBindingArgs other)
 {
     DoBind                   = other.DoBind;
     FieldSet_Name            = other.FieldSet_Name;
     FieldSet_FieldFlags      = other.FieldSet_FieldFlags;
     FieldSet_FieldType       = other.FieldSet_FieldType;
     TargetVariable_Name      = other.TargetVariable_Name;
     TargetVariable_Type      = other.TargetVariable_Type;
     TargetVariable_FieldInfo = other.TargetVariable_FieldInfo;
     Post      = other.Post;
     IsGroup   = other.IsGroup;
     GroupSize = other.GroupSize;
 }