Пример #1
0
        /// <summary>
        /// Sets the properties when called by the base class in response to the ApplySort call.
        /// Delegates to a helper method (ApplySortInternal) to do most of the work of the sorting.
        /// </summary>
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            m_SortDirection = direction;
            m_SortProperty  = prop;
            SortComparer <T> comparer = new SortComparer <T>(prop, direction);

            ApplySortInternal(comparer);
        }
    void IBindingListView.ApplySort(ListSortDescriptionCollection sorts)
    {
        m_SortProperty     = null;
        m_SortDescriptions = sorts;
        SortComparer <T> comparer = new SortComparer <T>(sorts);

        ApplySortInternal(comparer);
    }
Пример #3
0
            void sort(ILuaTable table, ILuaValue comp = null)
            {
                CheckNotNull("table.sort", table);
                var comparer = new SortComparer(E, comp);

                ILuaValue[] elems = unpack(table).OrderBy(k => k, comparer).ToArray();
                for (int i = 0; i < elems.Length; i++)
                {
                    ILuaValue ind = E.Runtime.CreateValue(i + 1);
                    table.SetItemRaw(ind, elems[i]);
                }
            }
Пример #4
0
        /*****************************************************************************/
        private IComparer <object> GetComparer(string[] sortFields)
        {
            var key = string.Join("", sortFields);

            if (_sortComparers.ContainsKey(key))
            {
                return(_sortComparers[key]);
            }

            var comparer = new SortComparer(sortFields);

            _sortComparers.Add(key, comparer);

            return(comparer);
        }
Пример #5
0
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            m_SortDirection = direction;
            m_SortProperty  = prop;
            var listRef = this.Items as List <T>;

            if (listRef == null)
            {
                return;
            }
            var comparer = new SortComparer <T>(prop, direction);

            listRef.Sort(comparer);

            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
        }
Пример #6
0
        public void SortHandler(object sender, DataGridSortingEventArgs e)
        {
            DataGridColumn column   = e.Column;
            IComparer      comparer = null;

            ListSortDirection direction = (column.SortDirection != ListSortDirection.Ascending)
                ? ListSortDirection.Ascending : ListSortDirection.Descending;

            column.SortDirection = direction;

            ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(data_grid.ItemsSource);

            comparer       = new SortComparer(direction == 0 ? false : true, e.Column.SortMemberPath);
            lcv.CustomSort = comparer;

            e.Handled = true;
        }
    private void ApplySortInternal(SortComparer <T> comparer)
    {
        if (m_OriginalCollection.Count == 0)
        {
            m_OriginalCollection.AddRange(this);
        }
        List <T> listRef = this.Items as List <T>;

        if (listRef == null)
        {
            return;
        }
        listRef.Sort(comparer);
        m_Sorted = true;
        OnListChanged(new ListChangedEventArgs(
                          ListChangedType.Reset, -1));
    }
Пример #8
0
        public static List <T> BubbleSort <T>(this List <T> original, SortComparer <T> comparer)
        {
            for (var i = 0; i < original.Count - 1; i++)
            {
                for (var j = i + 1; j < original.Count; j++)
                {
                    if (!comparer(original[i], original[j]))
                    {
                        continue;
                    }

                    var temp = original[i];
                    original[i] = original[j];
                    original[j] = temp;
                }
            }

            return(original);
        }
Пример #9
0
        /// <summary>
        /// Helper class to do the actual sorting work.
        /// </summary>
        private void ApplySortInternal(SortComparer <T> comparer)
        {
            //this causes the items in the collection maintained by the base class to be sorted
            //  according to the criteria provided to the BOSortComparer class.
            List <T> listRef = this.Items as List <T>;

            if (listRef == null)
            {
                return;
            }

            //let List<T> do the actual sorting based on your comparer
            listRef.Sort(comparer);
            m_Sorted = true;
            //fire an event through a call to the base class OnListChanged method indicating
            //  that the list has been changed.
            //Use 'reset' because it's likely that most members have been moved around.
            OnListChanged(new
                          ListChangedEventArgs(ListChangedType.Reset, -1));
        }
Пример #10
0
        private void PrepareMembersView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            var canWriteComparer = new UserCanWriteComparer();

            BindingOperations.SetBinding(canWriteComparer, UserCanWriteComparer.CurrentProcessProperty, new Binding("CurrentProcess")
            {
                Source = DataContext
            });
            BindingOperations.SetBinding(canWriteComparer, UserCanWriteComparer.SfDataGridProperty, new Binding()
            {
                Source = UsersGrid
            });
            var canWriteSortComparer = new SortComparer
            {
                Comparer     = canWriteComparer,
                PropertyName = "CanWrite"
            };

            var canReadComparer = new UserCanReadComparer();

            BindingOperations.SetBinding(canReadComparer, UserCanReadComparer.CurrentProcessProperty, new Binding("CurrentProcess")
            {
                Source = DataContext
            });
            BindingOperations.SetBinding(canReadComparer, UserCanReadComparer.SfDataGridProperty, new Binding()
            {
                Source = UsersGrid
            });
            var canReadSortComparer = new SortComparer
            {
                Comparer     = canReadComparer,
                PropertyName = "CanRead"
            };

            UsersGrid.SortComparers.AddRange(new []
            {
                canWriteSortComparer,
                canReadSortComparer
            });
        }
Пример #11
0
        public virtual bool variantsAreDistinct()
        {
            if (Varijante.Count < 2)
            {
                return(true);
            }

            PropertyDescriptor propDesc =
                TypeDescriptor.GetProperties(typeof(Element))["PodBroj"];
            SortComparer <Element> comparer = new SortComparer <Element>(propDesc, ListSortDirection.Ascending);
            List <Element>         copy     = new List <Element>(Varijante);

            copy.Sort(comparer);

            for (int i = 0; i < copy.Count - 1; i++)
            {
                if (copy[i].PodBroj == copy[i + 1].PodBroj)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #12
0
        /// <summary>
        /// 重写获取分页数据方法
        /// </summary>
        /// <param name="totalCount">总记录数</param>
        /// <param name="errorMsg">异常信息</param>
        /// <param name="permissionValidate">是否过滤权限</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="orderFields">排序字段</param>
        /// <param name="isDescs">是否降序</param>
        /// <param name="expression">条件表达式</param>
        /// <param name="whereSql">where语句</param>
        /// <param name="references">是否加载导航属性</param>
        /// <param name="connString">数据库连接字符串</param>
        /// <returns></returns>
        public override List <Sys_DbConfig> GetPageEntities(out long totalCount, out string errorMsg, bool permissionValidate = true, int pageIndex = 1, int pageSize = 10, List <string> orderFields = null, List <bool> isDescs = null, System.Linq.Expressions.Expression <Func <Sys_DbConfig, bool> > expression = null, string whereSql = null, List <string> fieldNames = null, bool references = false, string connString = null)
        {
            totalCount = 0;
            BaseDAL <Sys_Module> moduleDal = new BaseDAL <Sys_Module>(this.CurrUser);
            int dataSourceType             = (int)ModuleDataSourceType.DbTable;
            List <Sys_Module> modules      = expression == null?moduleDal.GetPageEntities(out totalCount, out errorMsg, permissionValidate, pageIndex, pageSize, null, null, x => x.DataSourceType == dataSourceType) : moduleDal.GetEntities(out errorMsg, x => x.DataSourceType == dataSourceType, null, permissionValidate);

            List <Sys_DbConfig> list = modules.Select(x => GetModuleCacheConfig(x.TableName, x.Name, x.Id)).ToList();
            //将未添加到模块表中的模块也加进来
            List <Type>   modelTypes = GetAllModelTypes();
            List <string> tables     = moduleDal.GetEntities(out errorMsg, x => x.TableName != null && x.TableName != string.Empty).Select(x => x.TableName).ToList();

            list.AddRange(modelTypes.Where(x => !tables.Contains(x.Name)).Select(x => GetModuleCacheConfig(x.Name)));
            if (expression != null)
            {
                list = list.Where(expression.Compile()).ToList();
                if (orderFields != null && orderFields.Count > 0)
                {
                    for (int i = 0; i < orderFields.Count; i++)
                    {
                        string orderField = string.IsNullOrEmpty(orderFields[i]) ? "Id" : orderFields[i];
                        bool   isdesc     = isDescs != null && orderFields.Count == isDescs.Count ? isDescs[i] : true;
                        SortComparer <Sys_DbConfig> reverser = new SortComparer <Sys_DbConfig>(typeof(Sys_DbConfig), orderField, isdesc ? ReverserInfo.Direction.DESC : ReverserInfo.Direction.ASC);
                        list.Sort(reverser);
                    }
                }
                totalCount = list.Count;
            }
            //页序号
            int index = pageIndex < 1 ? 0 : (pageIndex - 1);
            //每页记录数
            int rows = pageSize < 1 ? 10 : (pageSize > 2000 ? 2000 : pageSize);

            list = list.Skip <Sys_DbConfig>(rows * index).Take <Sys_DbConfig>(rows).ToList();
            return(list);
        }
Пример #13
0
        internal override void Sort(ScriptFunction compareFn)
        {
            SortComparer sc = new SortComparer(compareFn);

            System.Array.Sort(this.value, sc);
        }
Пример #14
0
 internal override void Sort(ScriptFunction compareFn){
   SortComparer sc = new SortComparer(compareFn);
   System.Array.Sort(this.value, sc);
 }
 internal override void Sort(ScriptFunction compareFn)
 {
     SortComparer comparer = new SortComparer(compareFn);
     Array.Sort(this.value, comparer);
 }
        internal override void Sort(ScriptFunction compareFn)
        {
            SortComparer comparer = new SortComparer(compareFn);

            Array.Sort(this.value, comparer);
        }