Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new SortExpressionCollection in which expr is the primary sort column
        /// </summary>
        /// <param name="other"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        /// <remarks>
        /// Case 1: expr is the first master expression -> It remains the first master expression and its
        /// direction is toggled
        /// Case 2: expr is a master expression but not the first -> It now becomes the first master expression
        /// Case 3: expr is the first sort expression -> It remainst the first sort expression and its direction is toggled
        /// Case 4: expr is a sort expr but not the first -> It now becomes the first sort expression
        /// Case 5: expr is not currently a sort or master expression -> It now becomes the only sort expression
        /// </remarks>
        public SortExpressionCollection(SortExpressionCollection other, SortExpression expr)
        {
            //int nIndex = other.IndexOfFirst(p => p.Equals(expr));
            int nIndex;

            if (other.Any())
            {
                nIndex = other.Select((p, i) => p.Equals(expr) ? i : -1).Max();
            }
            else
            {
                nIndex = -1;
            }
            _list = new List <SortExpression>(other._list);
            _indexOfFirstSortColumn = other._indexOfFirstSortColumn;
            if (nIndex == -1)
            {
                // Case 5: Not a sort or master expression
                _list.RemoveRange(_indexOfFirstSortColumn, _list.Count - _indexOfFirstSortColumn);
                _list.Insert(_indexOfFirstSortColumn, expr);
            }
            else if (nIndex < _indexOfFirstSortColumn)
            {
                // expr is master column
                if (nIndex == 0)
                {
                    // Case 1: First Master column. Toggle direction
                    _list[0] = _list[0].Toggle();
                }
                else
                {
                    // Case 2: Not the first master column. Make it first.
                    SortExpression temp = _list[0];
                    _list[0]      = expr;
                    _list[nIndex] = temp;
                }
            }
            else
            {
                // expr is a sort column
                if (nIndex == _indexOfFirstSortColumn)
                {
                    // Case 3: First sort column. Toggle direction
                    _list[nIndex] = _list[nIndex].Toggle();
                }
                else
                {
                    // Case 4: Not the first sort column. Make it first
                    SortExpression temp = _list[_indexOfFirstSortColumn];
                    _list[_indexOfFirstSortColumn] = expr;
                    _list[nIndex] = temp;
                }
            }
            _expression = EvaluateSortExpression();
        }
Ejemplo n.º 2
0
        protected override void RenderContents(HtmlTextWriter writer)
        {
//#if DEBUG
//            if (!_gv.PreSorted && string.IsNullOrEmpty(_gv.SortExpression))
//            {
//                throw new InvalidOperationException("You are attempting to display the " + _gv.ID + " list in an unsorted order");
//            }
//#endif
            if (this.HasControls())
            {
                // Must be HeaderTemplate of Template field. No sort icons to be displayed here
                base.RenderContents(writer);
                return;
            }
            SortExpression colSortExpression;
            int            nSortIndex;
            bool           bIsSortable = _gv.AllowSorting;

            if (string.IsNullOrEmpty(this.ContainingField.SortExpression))
            {
                bIsSortable       = false;
                nSortIndex        = -1;
                colSortExpression = null;
            }
            else
            {
                colSortExpression = new SortExpression(this.ContainingField.SortExpression);
                if (_gv.SortExpressions.Any())
                {
                    nSortIndex = _gv.SortExpressions.Select((p, i) => p.Equals(colSortExpression) ? i : -1).Max();
                }
                else
                {
                    nSortIndex = -1;
                }
            }


            if (this.ColumnSpan == 0)
            {
                // Case 1: Sortable with icon
                // Case 2: Sortable without icon
                // Case 3: Not sortable with icon
                // Case 4: Not sortable, no icon
                if (bIsSortable)
                {
                    // Sortable
                    SortExpressionCollection coll = new SortExpressionCollection(_gv.SortExpressions, colSortExpression);

                    //string script = string.Format("javascript:gridviewex_submit('{0}', '{1}', 'Sort${2}');",
                    //    this.Page.Form.ClientID, _gv.UniqueID, coll);
                    string script = string.Format("{0}", coll);

                    if (nSortIndex < 0)
                    {
                        // Case 2
                        RenderSortableNoIcon(writer, script);
                    }
                    else
                    {
                        colSortExpression = _gv.SortExpressions[nSortIndex];
                        RenderSortableWithIcon(writer, script, colSortExpression.GetSortDirection(), nSortIndex + 1);
                    }
                }
                else
                {
                    // Not sortable
                    if (nSortIndex < 0)
                    {
                        // Case 4
                        writer.Write(this.Text);
                    }
                    else
                    {
                        // Case 3
                        colSortExpression = _gv.SortExpressions[nSortIndex];
                        RenderNotSortableWithIcon(writer, this.Text, colSortExpression.GetSortDirection(), nSortIndex + 1);
                    }
                }
            }
            else
            {
                // Top row of the header should never have icons
                // Case 4
                writer.Write(this.Text);
            }
        }
Ejemplo n.º 3
0
 public bool Equals(SortExpressionCollection other)
 {
     throw new NotImplementedException();
 }