private void InitEdit()
        {
            Edit               = new XafBootstrapNumericEdit();
            Edit.Placeholder   = EditorHelper.GetPlaceholder(this, this.Caption);
            Edit.IsPassword    = Model.IsPassword;
            Edit.PropertyName  = PropertyName;
            Edit.RowCount      = Model.RowCount;
            Edit.OnClickScript = GetImmediatePostDataScript();

            String displayFormat = String.Concat(DisplayFormat);

            if (displayFormat == "")
            {
                ObjectCaptionFormatAttribute aAttr = (MemberInfo.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>());
                if (aAttr != null)
                {
                    displayFormat = aAttr.FormatString;
                }
            }
            if (displayFormat == "")
            {
                displayFormat = "{0:N0}";
            }
            Edit.DisplayFormat = displayFormat;
        }
示例#2
0
        private void AddObjToDropDown(object obj)
        {
            var memType = MemberInfo.MemberTypeInfo;

            if (memType.Type == typeof(SecuritySystemUser))
            {
                memType = XafTypesInfo.Instance.FindTypeInfo(SecuritySystem.UserType);
                try {
                    obj = Cast(obj, memType.Type);
                } catch (Exception e)
                {
                    return;
                }
            }

            String displayFormat = String.Concat(DisplayFormat);

            if (displayFormat == "")
            {
                try
                {
                    ObjectCaptionFormatAttribute aAttr = (memType.FindAttribute <ObjectCaptionFormatAttribute>());
                    if (aAttr != null)
                    {
                        displayFormat = aAttr.FormatString;
                    }
                    else
                    {
                        var lookupProperty = String.Concat(Model.GetValue <String>("LookupProperty"));
                        if (lookupProperty != "")
                        {
                            displayFormat = String.Format("{{0:{0}}}", lookupProperty);
                        }
                    }
                }
                catch
                {
                }
            }
            if (displayFormat == "")
            {
                displayFormat = "{0}";
            }

            var item     = DropDown.Items.Add();
            var App      = (WebApplication.Instance as XafApplication);
            var listView = (IModelListView)App.Model.Views[App.FindLookupListViewId(memType.Type)];
            var cols     = listView.Columns.Where(f => f.Index == null || f.Index > -1).OrderBy(f => f.Index);

            if (cols.Count() > 1)
            {
                var builder = new List <String>();
                foreach (var col in cols)
                {
                    builder.Add(String.Format(new ObjectFormatter(), "{0:" + col.GetValue <String>("FieldName") + "}", obj));
                }
                builder   = builder.Where(f => String.Concat(f) != "").ToList();
                item.Text = builder.First();
                item.Hint = String.Join("<br>", builder.Skip(1).Take(builder.Count - 1));
            }
            else
            {
                item.Text = String.Format(new ObjectFormatter(), String.Concat(displayFormat) == "" ? "{0}" : displayFormat, obj);
            }
            item.Value = obj;
        }
示例#3
0
        private void InitEdit()
        {
            var memType = MemberInfo.MemberTypeInfo;

            if (memType.Type == typeof(SecuritySystemUser))
            {
                memType = XafTypesInfo.Instance.FindTypeInfo(SecuritySystem.UserType);
            }

            CollectionOS = ObjectSpace.CreateNestedObjectSpace();

            Helper = new LookupEditorHelper(Application, CollectionOS, memType, Model);

            var bootstrapLookup = MemberInfo.FindAttribute <BootstrapLookupAttribute>();

            Boolean IsAuto = Helper.EditorMode == LookupEditorMode.Auto;

            if (Helper.EditorMode == LookupEditorMode.Auto)
            {
                Helper.EditorMode = LookupEditorMode.AllItemsWithSearch;
            }

            IsSelector = Helper.EditorMode == LookupEditorMode.AllItems;

            if (bootstrapLookup != null)
            {
                switch (bootstrapLookup.Kind)
                {
                case BootstapLookupKind.Auto:
                    IsSelector        = false;
                    Helper.EditorMode = LookupEditorMode.Auto;
                    break;

                case BootstapLookupKind.DropDown:
                    IsSelector        = false;
                    Helper.EditorMode = LookupEditorMode.AllItemsWithSearch;
                    break;

                case BootstapLookupKind.Selector:
                    IsSelector        = true;
                    Helper.EditorMode = LookupEditorMode.AllItemsWithSearch;
                    break;
                }
            }

            if (!IsSelector)
            {
                cs = Helper.CreateCollectionSource(Helper.ObjectSpace.GetObject(CurrentObject));
                if (IsAuto || (Helper.EditorMode == LookupEditorMode.AllItemsWithSearch && bootstrapLookup == null))
                {
                    IsSelector = cs != null && cs.List != null && (cs.List.Count == 0 || cs.List.Count > 20 || typeof(ITreeNode).IsAssignableFrom(MemberInfo.MemberType));
                }
            }

            if (cs != null && cs.List != null)
            {
                foreach (var item in NewObjects)
                {
                    cs.List.Add(cs.ObjectSpace.GetObject(item));
                }
            }

            String displayFormat = String.Concat(DisplayFormat);

            if (displayFormat == "")
            {
                try
                {
                    ObjectCaptionFormatAttribute aAttr = (MemberInfo.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>());
                    if (aAttr != null)
                    {
                        displayFormat = aAttr.FormatString;
                    }
                    else
                    {
                        var lookupProperty = String.Concat(Model.GetValue <String>("LookupProperty"));
                        if (lookupProperty != "")
                        {
                            displayFormat = String.Format("{{0:{0}}}", lookupProperty);
                        }
                    }
                }
                catch
                {
                }
            }
            if (displayFormat == "")
            {
                displayFormat = "{0}";
            }

            var App = (WebApplication.Instance as XafApplication);

            if (IsSelector)
            {
                DataSelector               = new XafBootstrapDataSelectorEdit(this, Application, ObjectSpace, Helper);
                DataSelector.Caption       = Model.Caption;
                DataSelector.PropertyName  = PropertyName;
                DataSelector.OnClickScript = GetImmediatePostDataScript();
                DataSelector.ListView      = (IModelListView)App.Model.Views[App.FindLookupListViewId(memType.Type)];
                DataSelector.DisplayFormat = displayFormat;
                DataSelector.OnCallback   += DataSelector_OnCallback;
                DataSelector.OnOk         += DataSelector_OnOk;
                DataSelector.OnCancel     += DataSelector_OnCancel;
            }
            else
            {
                DropDown = new XafBootstrapDropdownEdit();
                DropDown.OnClickScript = GetImmediatePostDataScript();

                if (cs != null && cs.List != null)
                {
                    var list          = cs.List.OfType <object>().ToList();
                    var modelListView = (IModelListView)App.Model.Views[App.FindLookupListViewId(memType.Type)];
                    if (modelListView != null && modelListView.Sorting.Count > 0)
                    {
                        DropDown.SortByText = false;
                        list = Helpers.SortListByViewSorting(modelListView, list).ToList();
                    }
                    foreach (var obj in list)
                    {
                        AddObjToDropDown(obj);
                    }
                }
            }

            CreateButtons();
        }
        private void SetValues()
        {
            Edit.Items.List.Clear();
            IList <TagSourceAttribute> tagSources = MemberInfo.FindAttributes <TagSourceAttribute>().ToList();
            var settingsAttribute = MemberInfo.FindAttribute <TagSettingsAttribute>();

            if (settingsAttribute != null)
            {
                Edit.Delimeter            = String.Concat(settingsAttribute.ValueSeparator);
                Edit.AllowAddCustomValues = settingsAttribute.AllowNew;
                Edit.AllowSelectValues    = settingsAttribute.AllowSelect;
            }

            IMemberInfo info;

            #region Set values from tag sources
            foreach (var tagSource in tagSources)
            {
                switch (tagSource.Kind)
                {
                case TagSourceKind.TypeSource:
                    if (typeof(Enum).IsAssignableFrom(tagSource.Type))
                    {
                        IList <String> Names  = Enum.GetNames(tagSource.Type);
                        Array          Values = Enum.GetValues(tagSource.Type);
                        String         format = String.Concat(tagSource.ValueFormat);
                        if (format == "")
                        {
                            format = "{0}";
                        }

                        for (int i = 0; i < Names.Count; i++)
                        {
                            String imageName = Helpers.GetXafImageName((Enum)Values.GetValue(i));
                            if (Edit.Items.List.Where(f => f.Text == String.Format(format, Names[i])).Count() == 0)
                            {
                                var item        = Edit.Items.Add();
                                var displayText = Helpers.GetXafDisplayName((Enum)Values.GetValue(i));
                                item.Text  = String.Format(format, displayText);
                                item.Value = String.Concat(Values.GetValue(i));
                                if (imageName == "")
                                {
                                    imageName = String.Concat(tagSource.ImageName);
                                }
                            }
                        }
                    }
                    else
                    {
                        var tagSourceType = tagSource.Type;
                        if (tagSourceType == typeof(SecuritySystemUser))
                        {
                            tagSourceType = SecuritySystem.UserType;
                        }

                        IObjectSpace os = ObjectSpace;

                        CollectionSource cs = new CollectionSource(os, tagSourceType);
                        if (tagSource.Criteria != null)
                        {
                            cs.Criteria["Criteria"] = PrepareCriteria(tagSource.Criteria);
                        }

                        String format = String.Concat(tagSource.ValueFormat);
                        if (format == "")
                        {
                            ITypeInfo TypeInfo = XafTypesInfo.Instance.FindTypeInfo(tagSourceType);
                            if (TypeInfo != null)
                            {
                                ObjectCaptionFormatAttribute attr = TypeInfo.FindAttribute <ObjectCaptionFormatAttribute>();
                                if (attr != null)
                                {
                                    format = attr.FormatString;
                                }
                                else
                                {
                                    var defPropAttr = TypeInfo.FindAttribute <XafDefaultPropertyAttribute>();
                                    if (defPropAttr != null)
                                    {
                                        format = "{0:" + defPropAttr.Name + "}";
                                    }
                                }
                            }
                        }

                        IList list = null;

                        switch (String.Concat(tagSource.Sorting).ToLower())
                        {
                        case "asc":
                        case "ascending":
                            list = cs.List.OfType <object>().OrderBy(f => String.Format(new ObjectFormatter(), format, f)).ToList();
                            break;

                        case "desc":
                        case "descending":
                            list = cs.List.OfType <object>().OrderByDescending(f => String.Format(new ObjectFormatter(), format, f)).ToList();
                            break;

                        default:
                            list = cs.List;
                            break;
                        }

                        foreach (object obj in list)
                        {
                            var text = String.Format(new ObjectFormatter(), format, obj);
                            if (Edit.Items.List.Where(f => f.Text == text).Count() == 0)
                            {
                                var item = Edit.Items.Add();
                                item.Text  = String.Format(new ObjectFormatter(), format, obj);
                                item.Value = String.Concat(ObjectFormatValues.GetValueRecursive(tagSource.Key, obj, out info));
                            }
                        }
                    }
                    break;

                case TagSourceKind.Values:
                    String Items = "";
                    try
                    {
                        Boolean      IsProperty = false;
                        var          property   = ObjectFormatValues.GetValueRecursive(tagSource.CommaValues, CurrentObject, out info);
                        IObjectSpace os         = ObjectSpace;

                        if (property is IEnumerable)
                        {
                            var coll = (property as IEnumerable);

                            var format = "";

                            if (info.MemberTypeInfo != null)
                            {
                                var attr = info.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>();
                                if (attr != null)
                                {
                                    format = attr.FormatString;
                                }
                                else
                                {
                                    var defPropAttr = info.MemberTypeInfo.FindAttribute <XafDefaultPropertyAttribute>();
                                    if (defPropAttr != null)
                                    {
                                        format = "{0:" + defPropAttr.Name + "}";
                                    }
                                }
                            }

                            Items = String.Join("*;*", coll.OfType <object>().Select(f => String.Format("{0}|{1}"
                                                                                                        , (format == "" ? f : String.Format(new ObjectFormatter(), format, f))
                                                                                                        , f is String ? String.Concat(f).Trim() : ObjectFormatValues.GetValueRecursive(os.GetKeyPropertyName(f.GetType()), f, out info))));
                            IsProperty = true;

                            if (String.Concat(tagSource.ValueFormat) != "")
                            {
                                format = tagSource.ValueFormat;
                            }

                            var selectCollection = coll.OfType <object>().Select(f => new
                            {
                                text  = (format == "" ? f : String.Format(new ObjectFormatter(), format, f)),
                                value = f is String ? String.Concat(f).Trim() : ObjectFormatValues.GetValueRecursive(String.Concat(tagSource.Key) == "" ? os.GetKeyPropertyName(f.GetType()) : tagSource.Key, f, out info)
                            }).GroupBy(f => f).Select(f => new { f.Key.text, f.Key.value }).OrderBy(f => f.text);

                            foreach (var item in selectCollection)
                            {
                                var tagItem = Edit.Items.Add();
                                tagItem.Text  = String.Concat(item.text).Trim();
                                tagItem.Value = String.Concat(item.value).Trim();
                            }
                        }
                        else
                        {
                            Items = String.Concat(property);

                            foreach (var item in String.Concat(tagSource.CommaValues).Split(',').Where(f => String.Concat(f) != ""))
                            {
                                if (Edit.Items.List.Where(f => f.Text == item.Split('|')[0]).Count() == 0)
                                {
                                    var tagItem = Edit.Items.Add();
                                    tagItem.Text = item.Split('|')[0];
                                    if (item.Split('|').Count() > 1)
                                    {
                                        tagItem.Value = item.Split('|')[1];
                                    }

                                    String imageName = tagSource.ImageName;
                                    if (item.Split('|').Count() > 2)
                                    {
                                        imageName = item.Split('|')[2];
                                    }
                                    if (imageName != "")
                                    {
                                        tagItem.ImageUrl = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo(tagSource.ImageName).ImageUrl;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Items = tagSource.CommaValues;
                    }

                    break;
                }
                foreach (var item in Edit.Items.List.ToList())
                {
                    if (String.Concat(item.Text) == "" && String.Concat(item.Value) == "")
                    {
                        Edit.Items.List.Remove(item);
                    }
                }
            }
            #endregion
        }
        private void InitEdit()
        {
            var Helper = new LookupEditorHelper(Application, ObjectSpace.CreateNestedObjectSpace(), MemberInfo.MemberTypeInfo, Model);

            IsSelector = Helper.EditorMode == LookupEditorMode.Search;

            CollectionSourceBase cs = null;

            if (!IsSelector)
            {
                cs = Helper.CreateCollectionSource(Helper.ObjectSpace.GetObject(CurrentObject));
                if (Helper.EditorMode == LookupEditorMode.Auto || Helper.EditorMode == LookupEditorMode.AllItemsWithSearch)
                {
                    IsSelector = cs != null && cs.List.Count > 20;
                }
            }

            String displayFormat = String.Concat(DisplayFormat);

            if (displayFormat == "")
            {
                try
                {
                    ObjectCaptionFormatAttribute aAttr = (MemberInfo.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>());
                    if (aAttr != null)
                    {
                        displayFormat = aAttr.FormatString;
                    }
                    else
                    {
                        var lookupProperty = String.Concat(Model.GetValue <String>("LookupProperty"));
                        if (lookupProperty != "")
                        {
                            displayFormat = String.Format("{{0:{0}}}", lookupProperty);
                        }
                    }
                }
                catch
                {
                }
            }
            if (displayFormat == "")
            {
                displayFormat = "{0}";
            }

            var App = (WebApplication.Instance as XafApplication);

            if (IsSelector)
            {
                DataSelector               = new XafBootstrapDataSelectorEdit(this, Application, ObjectSpace, Helper);
                DataSelector.Caption       = Model.Caption;
                DataSelector.PropertyName  = PropertyName;
                DataSelector.OnClickScript = GetImmediatePostDataScript();
                DataSelector.ListView      = (IModelListView)App.Model.Views[App.FindLookupListViewId(MemberInfo.MemberType)];
                DataSelector.DisplayFormat = displayFormat;
            }
            else
            {
                DropDown = new XafBootstrapDropdownEdit();
                DropDown.OnClickScript = GetImmediatePostDataScript();
                var listView = (IModelListView)App.Model.Views[App.FindLookupListViewId(MemberInfo.MemberType)];
                if (cs != null)
                {
                    foreach (var obj in cs.List)
                    {
                        var item = DropDown.Items.Add();
                        var cols = listView.Columns.Where(f => f.Index == null || f.Index > -1).OrderBy(f => f.Index);
                        if (cols.Count() > 1)
                        {
                            var builder = new List <String>();
                            foreach (var col in cols)
                            {
                                builder.Add(String.Format(new ObjectFormatter(), "{0:" + col.GetValue <String>("FieldName") + "}", obj));
                            }
                            builder   = builder.Where(f => String.Concat(f) != "").ToList();
                            item.Text = builder.First();
                            item.Hint = String.Join("<br>", builder.Skip(1).Take(builder.Count - 1));
                        }
                        else
                        {
                            item.Text = String.Format(new ObjectFormatter(), String.Concat(displayFormat) == "" ? "{0}" : displayFormat, obj);
                        }
                        item.Value = ObjectSpace.GetObject(obj);
                    }
                }
            }
        }
        private void SetValues()
        {
            Edit.Items.List.Clear();
            IList <TagSourceAttribute> tagSources = MemberInfo.FindAttributes <TagSourceAttribute>().ToList();
            IMemberInfo info;

            #region Set values from tag sources
            foreach (var tagSource in tagSources)
            {
                switch (tagSource.Kind)
                {
                case TagSourceKind.TypeSource:
                    if (typeof(Enum).IsAssignableFrom(tagSource.Type))
                    {
                        IList <String> Names  = Enum.GetNames(tagSource.Type);
                        Array          Values = Enum.GetValues(tagSource.Type);
                        String         format = String.Concat(tagSource.ValueFormat);
                        if (format == "")
                        {
                            format = "{0}";
                        }

                        for (int i = 0; i < Names.Count; i++)
                        {
                            String imageName = Helpers.GetXafImageName((Enum)Values.GetValue(i));
                            if (Edit.Items.List.Where(f => f.Text == String.Format(format, Names[i])).Count() == 0)
                            {
                                var item = Edit.Items.Add();
                                item.Text  = String.Format(format, Names[i]);
                                item.Value = String.Concat(Values.GetValue(i));
                                if (imageName == "")
                                {
                                    imageName = String.Concat(tagSource.ImageName);
                                }
                            }
                        }
                    }
                    else
                    {
                        IObjectSpace os = (WebApplication.Instance as XafApplication).CreateObjectSpace(tagSource.Type);

                        CollectionSource cs = new CollectionSource(os, tagSource.Type);
                        if (tagSource.Criteria != null)
                        {
                            cs.Criteria["Criteria"] = PrepareCriteria(tagSource.Criteria);
                        }

                        String format = String.Concat(tagSource.ValueFormat);
                        if (format == "")
                        {
                            ITypeInfo TypeInfo = XafTypesInfo.Instance.FindTypeInfo(tagSource.Type);
                            if (TypeInfo != null)
                            {
                                ObjectCaptionFormatAttribute attr = TypeInfo.FindAttribute <ObjectCaptionFormatAttribute>();
                                if (attr != null)
                                {
                                    format = attr.FormatString;
                                }
                                else
                                {
                                    var defPropAttr = TypeInfo.FindAttribute <XafDefaultPropertyAttribute>();
                                    if (defPropAttr != null)
                                    {
                                        format = "{0:" + defPropAttr.Name + "}";
                                    }
                                }
                            }
                        }

                        IList list = null;

                        switch (String.Concat(tagSource.Sorting).ToLower())
                        {
                        case "asc":
                        case "ascending":
                            list = cs.List.OfType <object>().OrderBy(f => String.Format(new ObjectFormatter(), format, f)).ToList();
                            break;

                        case "desc":
                        case "descending":
                            list = cs.List.OfType <object>().OrderByDescending(f => String.Format(new ObjectFormatter(), format, f)).ToList();
                            break;

                        default:
                            list = cs.List;
                            break;
                        }

                        foreach (object obj in list)
                        {
                            var text = String.Format(new ObjectFormatter(), format, obj);
                            if (Edit.Items.List.Where(f => f.Text == text).Count() == 0)
                            {
                                var item = Edit.Items.Add();
                                item.Text  = String.Format(new ObjectFormatter(), format, obj);
                                item.Value = String.Concat(ObjectFormatValues.GetValueRecursive(tagSource.Key, obj, out info));
                            }
                        }
                    }
                    break;

                case TagSourceKind.Values:
                    String Items = "";
                    try
                    {
                        Boolean      IsProperty = false;
                        var          property   = ObjectFormatValues.GetValueRecursive(tagSource.CommaValues, CurrentObject, out info);
                        IObjectSpace os         = (WebApplication.Instance as XafApplication).CreateObjectSpace(CurrentObject.GetType());

                        if (property is IEnumerable)
                        {
                            var coll = (property as IEnumerable);

                            var format = "";

                            if (info.MemberTypeInfo != null)
                            {
                                var attr = info.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>();
                                if (attr != null)
                                {
                                    format = attr.FormatString;
                                }
                                else
                                {
                                    var defPropAttr = info.MemberTypeInfo.FindAttribute <XafDefaultPropertyAttribute>();
                                    if (defPropAttr != null)
                                    {
                                        format = "{0:" + defPropAttr.Name + "}";
                                    }
                                }
                            }

                            Items = String.Join(",", coll.OfType <object>().Select(f => String.Format("{0}|{1}"
                                                                                                      , (format == "" ? f : String.Format(new ObjectFormatter(), format, f))
                                                                                                      , ObjectFormatValues.GetValueRecursive(os.GetKeyPropertyName(f.GetType()), f, out info))));
                            IsProperty = true;
                        }
                        else
                        {
                            Items = String.Concat(property);
                        }
                        if (!IsProperty)
                        {
                            Items = tagSource.CommaValues;
                        }
                    }
                    catch (Exception ex)
                    {
                        Items = tagSource.CommaValues;
                    }
                    foreach (var item in Items.Split(',').Where(f => String.Concat(f) != ""))
                    {
                        if (Edit.Items.List.Where(f => f.Text == item.Split('|')[0]).Count() == 0)
                        {
                            var tagItem = Edit.Items.Add();
                            tagItem.Text = item.Split('|')[0];
                            if (item.Split('|').Count() > 1)
                            {
                                tagItem.Value = item.Split('|')[1];
                            }

                            String imageName = tagSource.ImageName;
                            if (item.Split('|').Count() > 2)
                            {
                                imageName = item.Split('|')[2];
                            }
                            if (imageName != "")
                            {
                                tagItem.ImageUrl = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo(tagSource.ImageName).ImageUrl;
                            }
                        }
                    }
                    break;
                }
            }
            #endregion
        }