Пример #1
0
        public void SortBy(SortCol col)
        {
            _sortCols.Clear();
            _sortCols.Add(col);
            if (_lazyLoadPages)
            {
                // Clear page cache
                //scolson: Use ClearPageCache routine instead of nulling the data list.
                this.ClearPageCache();
                //_data = new List<Entity>();
                this.paging.extraInfo = "";
                Refresh();
            }
            else
            {
                // From SlickGrid : an extra reversal for descending sort keeps the sort stable
                // (assuming a stable native sort implementation, which isn't true in some cases)
                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
                _data.Sort(delegate(Entity a, Entity b) { return(Entity.SortDelegate(col.AttributeName, a, b)); });

                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
            }
        }
Пример #2
0
        public override void Sort(SortColData sorting)
        {

            _sortColumn = new SortCol(sorting.SortCol.Field, sorting.SortAsc);

            Refresh();
        }
Пример #3
0
        public ConnectionsViewModel(EntityReference parentRecordId, string[] connectToTypes, int pageSize, FetchQuerySettings view)
        {
            Connections = new EntityDataViewModel(pageSize, typeof(Connection), true);
            if (view != null)
            {
                _viewFetchXml = QueryParser.GetFetchXmlParentFilter(view, "record1id");
                // Set initial sort
                _defaultSortCol=new SortCol(view.OrderByAttribute, !view.OrderByDesending);
            }
           
            ParentRecordId.SetValue(parentRecordId);
         
            ObservableConnection connection = new ObservableConnection(connectToTypes);
            connection.Record2Id.SetValue(parentRecordId);
            ConnectionEdit = (Observable<ObservableConnection>)ValidatedObservableFactory.ValidatedObservable(connection);

            Connections.OnDataLoaded.Subscribe(Connections_OnDataLoaded);
            ConnectionEdit.GetValue().OnSaveComplete += ConnectionsViewModel_OnSaveComplete;
            ObservableConnection.RegisterValidation(Connections.ValidationBinder);
            AllowAddNew = Knockout.DependentObservable<bool>(AllowAddNewComputed);
        }
Пример #4
0
        public override void Sort(SortColData sorting)
        {


            SortCol col = new SortCol(sorting.SortCol.Field,sorting.SortAsc);
           
            SortBy(col);
        }
Пример #5
0
 public void SortBy(SortCol col)
 {
     _sortCols.Clear();
     _sortCols.Add(col);
     if (_lazyLoadPages)
     {
         // Clear page cache
         //scolson: Use ClearPageCache routine instead of nulling the data list.
         this.ClearPageCache();
         //_data = new List<Entity>();
         this.paging.extraInfo = "";
         Refresh();
     }
     else
     {
         // From SlickGrid : an extra reversal for descending sort keeps the sort stable
         // (assuming a stable native sort implementation, which isn't true in some cases)
         if (col.Ascending == false)
         {
             _data.Reverse();
         }
         _data.Sort(delegate(Entity a, Entity b) { return Entity.SortDelegate(col.AttributeName, a, b); });
         
         if (col.Ascending == false)
         {
             _data.Reverse();
         }
     }
 }
Пример #6
0
        public override void Sort(SortColData sorting)
        {
            SortCol col = new SortCol(sorting.SortCol.Field, sorting.SortAsc);

            SortBy(col);
        }
        public void SortBy(SortCol col)
        {
            _sortCols.Clear();
            _sortCols.Add(col);
            if (_lazyLoadPages)
            {
                // Clear page cache
                _data = new List<Entity>();
                this.paging.extraInfo = "";
                Refresh();
            }
            else
            {
                // From SlickGrid : an extra reversal for descending sort keeps the sort stable
                // (assuming a stable native sort implementation, which isn't true in some cases)
                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
                _data.Sort(delegate(Entity a, Entity b)
                {

                    object l = a.GetAttributeValue(col.AttributeName);
                    object r = b.GetAttributeValue(col.AttributeName);
                    decimal result = 0;

                    string typeName = "";
                    if (l != null)
                        typeName = l.GetType().Name;
                    else if (r != null)
                        typeName = r.GetType().Name;

                    if (l != r)
                    {
                        switch (typeName.ToLowerCase())
                        {
                            case "string":
                                l = l != null ? ((string)l).ToLowerCase() : null;
                                r = r != null ? ((string)r).ToLowerCase() : null;
                                if ((bool)Script.Literal("{0}<{1}", l, r))
                                    result = -1;
                                else
                                    result = 1;
                                break;
                            case "date":
                                if ((bool)Script.Literal("{0}<{1}", l, r))
                                    result = -1;
                                else
                                    result = 1;
                                break;
                            case "number":
                                decimal ln = l != null ? ((decimal)l) : 0;
                                decimal rn = r != null ? ((decimal)r) : 0;
                                result = (ln - rn);
                                break;
                            case "money":
                                decimal lm = l != null ? ((Money)l).Value : 0;
                                decimal rm = r != null ? ((Money)r).Value : 0;
                                result = (lm - rm);
                                break;
                            case "optionsetvalue":
                                int? lo = l != null ? ((OptionSetValue)l).Value : 0;
                                lo = lo != null ? lo : 0;
                                int? ro = r != null ? ((OptionSetValue)r).Value : 0;
                                ro = ro != null ? ro : 0;
                                result = (decimal)(lo - ro);
                                break;
                            case "entityreference":
                                string le = (l != null) && (((EntityReference)l).Name != null) ? ((EntityReference)l).Name : "";
                                string re = r != null && (((EntityReference)r).Name != null) ? ((EntityReference)r).Name : "";
                                if ((bool)Script.Literal("{0}<{1}", le, re))
                                    result = -1;
                                else
                                    result = 1;
                                break;

                        }
                    }
                    return (int)result;
                });

                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
            }
        }
Пример #8
0
        public void SortBy(SortCol col)
        {
            _sortCols.Clear();
            _sortCols.Add(col);
            if (_lazyLoadPages)
            {
                // Clear page cache
                _data = new List <Entity>();
                this.paging.extraInfo = "";
                Refresh();
            }
            else
            {
                // From SlickGrid : an extra reversal for descending sort keeps the sort stable
                // (assuming a stable native sort implementation, which isn't true in some cases)
                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
                _data.Sort(delegate(Entity a, Entity b)
                {
                    object l       = a.GetAttributeValue(col.AttributeName);
                    object r       = b.GetAttributeValue(col.AttributeName);
                    decimal result = 0;

                    string typeName = "";
                    if (l != null)
                    {
                        typeName = l.GetType().Name;
                    }
                    else if (r != null)
                    {
                        typeName = r.GetType().Name;
                    }

                    if (l != r)
                    {
                        switch (typeName.ToLowerCase())
                        {
                        case "string":
                            l = l != null ? ((string)l).ToLowerCase() : null;
                            r = r != null ? ((string)r).ToLowerCase() : null;
                            if ((bool)Script.Literal("{0}<{1}", l, r))
                            {
                                result = -1;
                            }
                            else
                            {
                                result = 1;
                            }
                            break;

                        case "date":
                            if ((bool)Script.Literal("{0}<{1}", l, r))
                            {
                                result = -1;
                            }
                            else
                            {
                                result = 1;
                            }
                            break;

                        case "number":
                            decimal ln = l != null ? ((decimal)l) : 0;
                            decimal rn = r != null ? ((decimal)r) : 0;
                            result     = (ln - rn);
                            break;

                        case "money":
                            decimal lm = l != null ? ((Money)l).Value : 0;
                            decimal rm = r != null ? ((Money)r).Value : 0;
                            result     = (lm - rm);
                            break;

                        case "optionsetvalue":
                            int?lo = l != null ? ((OptionSetValue)l).Value : 0;
                            lo     = lo != null ? lo : 0;
                            int?ro = r != null ? ((OptionSetValue)r).Value : 0;
                            ro     = ro != null ? ro : 0;
                            result = (decimal)(lo - ro);
                            break;

                        case "entityreference":
                            string le = (l != null) && (((EntityReference)l).Name != null) ? ((EntityReference)l).Name : "";
                            string re = r != null && (((EntityReference)r).Name != null) ? ((EntityReference)r).Name : "";
                            if ((bool)Script.Literal("{0}<{1}", le, re))
                            {
                                result = -1;
                            }
                            else
                            {
                                result = 1;
                            }
                            break;
                        }
                    }
                    return((int)result);
                });

                if (col.Ascending == false)
                {
                    _data.Reverse();
                }
            }
        }
Пример #9
0
        private void SortBy(SortCol col,List<object> data)
        {
            // From SlickGrid : an extra reversal for descending sort keeps the sort stable
            // (assuming a stable native sort implementation, which isn't true in some cases)
            if (col.Ascending == false)
            {
                data.Reverse();
            }
            data.Sort(delegate(object a, object b)
            {
         
                object l = ((Dictionary<string,object>)a)[col.AttributeName];
                object r = ((Dictionary<string, object>)b)[col.AttributeName];
                decimal result = 0;

                string typeName = "";
                if (l != null)
                    typeName = l.GetType().Name;
                else if (r != null)
                    typeName = r.GetType().Name;

                if (l != r)
                {
                    switch (typeName.ToLowerCase())
                    {
                        case "string":
                            l = l != null ? ((string)l).ToLowerCase() : null;
                            r = r != null ? ((string)r).ToLowerCase() : null;
                            if ((bool)Script.Literal("{0}<{1}", l, r))
                                result = -1;
                            else
                                result = 1;
                            break;
                        case "date":
                            if ((bool)Script.Literal("{0}<{1}", l, r))
                                result = -1;
                            else
                                result = 1;
                            break;
                        case "number":
                            decimal ln = l != null ? ((decimal)l) : 0;
                            decimal rn = r != null ? ((decimal)r) : 0;
                            result = (ln - rn);
                            break;
                        case "money":
                            decimal lm = l != null ? ((Money)l).Value : 0;
                            decimal rm = r != null ? ((Money)r).Value : 0;
                            result = (lm - rm);
                            break;
                        case "optionsetvalue":
                            int? lo = l != null ? ((OptionSetValue)l).Value : 0;
                            lo = lo != null ? lo : 0;
                            int? ro = r != null ? ((OptionSetValue)r).Value : 0;
                            ro = ro != null ? ro : 0;
                            result = (decimal)(lo - ro);
                            break;
                        case "entityreference":
                            string le = (l != null) && (((EntityReference)l).Name != null) ? ((EntityReference)l).Name : "";
                            string re = r != null && (((EntityReference)r).Name != null) ? ((EntityReference)r).Name : "";
                            if ((bool)Script.Literal("{0}<{1}", le, re))
                                result = -1;
                            else
                                result = 1;
                            break;

                    }
                }
                return (int)result;
            });

            if (col.Ascending == false)
            {
                data.Reverse();
            }

        }