예제 #1
0
        /// <summary>
        /// Doing data exchange: control ==> object
        /// </summary>
        public bool OnOk()
        {
            foreach (KeyValuePair <string, PropertyCtrlInfo> kv in _controlMap)
            {
                PropertyCtrlInfo ci = kv.Value;
                if (ci.Converter != null)
                {
                    ci.PropertyInfo.SetValue(ci.ParentObject, ci.Converter.ToPropertyValue(ci.Binder.Value), null);
                }
                else
                {
                    ci.PropertyInfo.SetValue(ci.ParentObject, ci.Binder.Value, null);
                }
            }

            return(true);
        }
예제 #2
0
        private void AddControlInfo(Page page, PropertyCtrlInfo ci, ObjIdentifier parentId)
        {
            Debug.Assert(ci.Binder.Control != null);

            switch (ci.Layout.Section)
            {
            case Section.Header:
                page.HeadCtrls.Add(ci); break;

            case Section.Footer:
                page.FootCtrls.Add(ci); break;

            case Section.Body:
            default:
                page.BodyCtrls.Add(ci); break;
            }

            ci.Identifier = new ObjIdentifier(ci.PropertyInfo.Name, parentId);
            _controlMap.Add(ci.Identifier.FullName, ci);
        }
예제 #3
0
        private void LoadComposite(Type tp, object typeObj, string objName)
        {
            PropertyInfo[] properties = tp.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo pi in properties)
            {
                Type unerLyingType = TypeInterrogator.GetUnderlyingType(pi.PropertyType);
                if (IsSkipped(pi, unerLyingType))
                {
                    continue;
                }

                if (IsLeafCtrl(unerLyingType) || IsCollectionCtrl(unerLyingType))
                {
                    PropertyCtrlInfo pci = _controlMap[PropertyInterrogator.GetFullName(pi)];
                    pci.ParentObject = typeObj;
                    pci.Binder.Value = pi.GetValue(typeObj, null);
                }
                else
                {
                    LoadComposite(unerLyingType, pi.GetValue(typeObj, null), pi.Name);
                }
            }
        }
예제 #4
0
        private PropertyCtrlInfo BuildControlInfo(PropertyInfo pi, object parentObj)
        {
            PropertyCtrlInfo ci = new PropertyCtrlInfo();

            ci.PropertyInfo = pi;
            ci.ParentObject = parentObj;

            ci.Layout = AttributeInterrogator.GetAttribute <LayoutHint>(pi);
            if (ci.Layout == null)
            {
                ci.Layout = new LayoutHint();
            }

            if (_objHints.LabelHints != null && _objHints.LabelHints.ContainsKey(pi.Name))
            {
                ci.Layout.Label = _objHints.LabelHints[pi.Name];
            }
            if (string.IsNullOrEmpty(ci.Layout.Label))
            {
                ci.Layout.Label = NameCleaner.ToPhrase(pi.Name);
            }

            return(ci);
        }
예제 #5
0
        private void BuildCollectionCtrl(PropertyInfo pi, Type tp, object parentObj, ObjIdentifier parentId)
        {
            PropertyCtrlInfo ci   = BuildControlInfo(pi, parentObj);
            Page             page = (ci.Layout.IsAdvanced) ? Macros.SafeGet(ref _advancedPage) : _mainPage;

            object piValue = (parentObj == null) ? null : pi.GetValue(parentObj, null);

            Type itemT = TypeInterrogator.GetItemType(tp);

            if (TypeInterrogator.IsSingleValueType(itemT))
            {
                if (TypeInterrogator.IsEnumType(itemT))
                {
                    BitFlagsPCV converter = new BitFlagsPCV(itemT);
                    ci.Binder    = new CheckedListBoxBinder(converter.ToControlValue(itemT), converter.ToControlValue((IEnumerable)piValue));
                    ci.Converter = converter;
                }
                else if (TypeInterrogator.IsStringType(itemT))
                {
                    if (TypeInterrogator.IsArrayType(tp))
                    {
                        ci.Converter = new ArrayPCV(itemT);
                    }
                    else if (TypeInterrogator.IsListType(tp))
                    {
                        ci.Converter = new ListPCV(itemT);
                    }

                    if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name))
                    {
                        ci.Binder = new ListBoxBinder(_objHints.ValueHints[pi.Name], (IEnumerable <string>)piValue);
                    }
                    else
                    {
                        ci.Binder = new ListBoxBinder((IEnumerable <string>)piValue);
                    }
                }
                else if (TypeInterrogator.IsNumericType(itemT))
                {
                    if (TypeInterrogator.IsArrayType(tp))
                    {
                        ci.Converter = new ArrayPCV(itemT);
                    }
                    else if (TypeInterrogator.IsListType(tp))
                    {
                        ci.Converter = new ListPCV(itemT);
                    }

                    if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name))
                    {
                        ci.Binder = new ListBoxBinder(_objHints.ValueHints[pi.Name], CollConverter.ToStringArray((IEnumerable)piValue));
                    }
                    else
                    {
                        ci.Binder = new ListBoxBinder(CollConverter.ToStringArray((IEnumerable)piValue));
                    }
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            else
            {
                ci.Binder = new ObjCollectionBinder((IEnumerable)piValue, null);
            }

            AddControlInfo(page, ci, parentId);
        }
예제 #6
0
        private void BuildLeafCtrl(PropertyInfo pi, Type tp, object parentObj, ObjIdentifier parentId)
        {
            PropertyCtrlInfo ci   = BuildControlInfo(pi, parentObj);
            Page             page = (ci.Layout.IsAdvanced) ? Macros.SafeGet(ref _advancedPage) : _mainPage;

            object piValue = (parentObj == null) ? null : pi.GetValue(parentObj, null);

            if (TypeInterrogator.IsNumericType(tp))
            {
                DecimalPCV converter = new DecimalPCV(tp);
                ci.Converter = converter;

                NumericUpDownHint upDownHint = AttributeInterrogator.GetAttribute <NumericUpDownHint>(pi);
                if (upDownHint != null)
                {
                    ci.Binder = new NumericUpDownSingleBinder((piValue == null) ? Decimal.MinValue : Decimal.Parse(piValue.ToString()), upDownHint);
                }
                else
                {
                    TextBoxHint tbHint = AttributeInterrogator.GetAttribute <TextBoxHint>(pi);
                    if (tbHint == null)
                    {
                        tbHint = new TextBoxHint();
                    }
                    tbHint.CharsAccepted = TextBoxHint.Numbers;
                    ci.Binder            = new TextBoxBinder((piValue == null) ? null : piValue.ToString(), tbHint);
                }
            }
            else if (TypeInterrogator.IsBoolType(tp))
            {
                ci.Binder         = new CheckBoxBinder(ci.Layout.Label, (piValue == null) ? false : (bool)piValue);
                ci.Layout.Label   = null;
                ci.Layout.Section = Section.Footer;
            }
            else if (TypeInterrogator.IsDateTimeType(tp))
            {
                ci.Binder = new DateTimePickerBinder((piValue == null) ? DateTime.Today : (DateTime)piValue, null);
            }
            else if (TypeInterrogator.IsEnumType(tp))
            {
                const int MaxRadioButtonCount = 3;

                IEnumerable <string> names = EnumConverter.ToNames(tp, true);
                if (CollConverter.GetCount(names) <= MaxRadioButtonCount)
                {
                    ci.Binder = new RadioButtonBinder(tp, (piValue == null) ? -1 : (int)piValue);
                }
                else
                {
                    EnumPCV converter = new EnumPCV(tp);
                    ci.Binder    = new ComboBoxBinder(piValue.ToString(), names, ComboBoxStyle.DropDownList);
                    ci.Converter = converter;
                }
            }
            else if (TypeInterrogator.IsStringType(tp))
            {
                if (_objHints.ValueHints != null && _objHints.ValueHints.ContainsKey(pi.Name))
                {
                    ci.Binder = new ComboBoxBinder((piValue == null) ? null : piValue.ToString(), _objHints.ValueHints[pi.Name], ComboBoxStyle.DropDown);
                }
                else
                {
                    LayoutHint lhint = AttributeInterrogator.GetAttribute <LayoutHint>(pi);
                    ci.Binder = new TextBoxBinder((piValue == null) ? null : piValue.ToString(), lhint);
                }
            }
            else if (tp == typeof(System.Data.DataTable))
            {
                ci.Binder             = new DataGridViewBinder((piValue == null) ? null : piValue as System.Data.DataTable);
                ci.Layout.ColumnCount = 2;
            }
            else if (TypeInterrogator.IsDictionaryType(tp))
            {
                DictionaryPCV converter = new DictionaryPCV();
                Dictionary <string, string> converted = (piValue == null) ? null : converter.ToControlValue(piValue);
                ci.Binder    = new DictionaryCtrlBinder(converted, _objHints.DictionaryHint);
                ci.Converter = converter;

                ci.Layout.Label       = null;
                ci.Layout.ColumnCount = 2;
                ci.Layout.RowCount    = (converted != null) ? (int)((converted.Count + 1) * 1.5) : 2;
            }
            AddControlInfo(page, ci, parentId);
        }