Пример #1
0
        ///<summary>
        ///Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        ///</summary>
        ///
        ///<returns>
        ///Value Condition Less than zerox is less than y.Zerox equals y.Greater than zerox is greater than y.
        ///</returns>
        ///
        ///<param name="y">The second object to compare.</param>
        ///<param name="x">The first object to compare.</param>
        public virtual int Compare(GridViewRowInfo x, GridViewRowInfo y)
        {
            var first  = ((CustomCell)x.Cells[ColumnIndex].Tag);
            var second = ((CustomCell)y.Cells[ColumnIndex].Tag);

            if (first.Tag == null || second.Tag == null)
            {
                return(SortMultiplier * string.Compare(first.Text, second.Text));
            }
            if (first.Tag is AtaChapter && second.Tag is AtaChapter)
            {
                return(ComparerMethods.ATAComparer(first.Text, second.Text) *
                       SortMultiplier);
            }
            if (first.Tag is DirectiveStatus && second.Tag is DirectiveStatus)
            {
                return(ComparerMethods.DirectiveStatusComparer((DirectiveStatus)first.Tag,
                                                               (DirectiveStatus)second.Tag) *
                       SortMultiplier);
            }
            if (first.Tag is DateTime && second.Tag is DateTime)
            {
                DateTime xValue = (DateTime)first.Tag;
                DateTime yValue = (DateTime)second.Tag;
                return(SortMultiplier * DateTime.Compare(yValue, xValue));
            }
            if (first.Tag is string && second.Tag is string)
            {
                int i, j;
                if (int.TryParse(first.Text, out i) && int.TryParse(second.Text, out j))
                {
                    return(SortMultiplier * (i - j));
                }

                return(SortMultiplier * string.Compare(first.Text, second.Text));
            }
            if (first.Tag is int && second.Tag is int)
            {
                int xValue = (int)first.Tag;
                int yValue = (int)second.Tag;
                return(SortMultiplier * (yValue - xValue));
            }
            if (first.Tag is double && second.Tag is double)
            {
                double xValue = (double)first.Tag;
                double yValue = (double)second.Tag;
                return(SortMultiplier * (int)(yValue - xValue));
            }
            if (first.Tag as IComparable != null && (first.Tag.GetType().Equals(second.Tag.GetType())))
            {
                try
                {
                    return(SortMultiplier * ((IComparable)first.Tag).CompareTo(second.Tag));
                }
                catch
                {
                }
            }
            return(SortMultiplier * string.Compare(first.Text, second.Text));
        }
Пример #2
0
        ///<summary>
        ///Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        ///</summary>
        ///
        ///<returns>
        ///Value Condition Less than zerox is less than y.Zerox equals y.Greater than zerox is greater than y.
        ///</returns>
        ///
        ///<param name="y">The second object to compare.</param>
        ///<param name="x">The first object to compare.</param>
        public virtual int Compare(ListViewItem x, ListViewItem y)
        {
            if (x.SubItems[ColumnIndex].Tag == null || y.SubItems[ColumnIndex].Tag == null)
            {
                return(SortMultiplier * string.Compare(x.SubItems[ColumnIndex].Text, y.SubItems[ColumnIndex].Text));
            }
            if (x.SubItems[ColumnIndex].Tag is AtaChapter && y.SubItems[ColumnIndex].Tag is AtaChapter)
            {
                return(ComparerMethods.ATAComparer(x.SubItems[ColumnIndex].Text, y.SubItems[ColumnIndex].Text) *
                       SortMultiplier);
            }
            if (x.SubItems[ColumnIndex].Tag is DirectiveStatus && y.SubItems[ColumnIndex].Tag is DirectiveStatus)
            {
                return(ComparerMethods.DirectiveStatusComparer((DirectiveStatus)x.SubItems[ColumnIndex].Tag,
                                                               (DirectiveStatus)y.SubItems[ColumnIndex].Tag) *
                       SortMultiplier);
            }
            if (x.SubItems[ColumnIndex].Tag is DateTime && y.SubItems[ColumnIndex].Tag is DateTime)
            {
                DateTime xValue = (DateTime)x.SubItems[ColumnIndex].Tag;
                DateTime yValue = (DateTime)y.SubItems[ColumnIndex].Tag;
                return(SortMultiplier * DateTime.Compare(yValue, xValue));
            }
            if (x.SubItems[ColumnIndex].Tag is string && y.SubItems[ColumnIndex].Tag is string)
            {
                int i, j;
                if (int.TryParse(x.SubItems[ColumnIndex].Text, out i) && int.TryParse(y.SubItems[ColumnIndex].Text, out j))
                {
                    return(SortMultiplier * (i - j));
                }

                return(SortMultiplier * string.Compare(x.SubItems[ColumnIndex].Text, y.SubItems[ColumnIndex].Text));
            }
            if (x.SubItems[ColumnIndex].Tag is int && y.SubItems[ColumnIndex].Tag is int)
            {
                int xValue = (int)x.SubItems[ColumnIndex].Tag;
                int yValue = (int)y.SubItems[ColumnIndex].Tag;
                return(SortMultiplier * (yValue - xValue));
            }
            if (x.SubItems[ColumnIndex].Tag is double && y.SubItems[ColumnIndex].Tag is double)
            {
                double xValue = (double)x.SubItems[ColumnIndex].Tag;
                double yValue = (double)y.SubItems[ColumnIndex].Tag;
                return(SortMultiplier * (int)(yValue - xValue));
            }
            if (x.SubItems[ColumnIndex].Tag as IComparable != null && (x.SubItems[ColumnIndex].Tag.GetType().Equals(y.SubItems[ColumnIndex].Tag.GetType())))
            {
                try
                {
                    return(SortMultiplier * ((IComparable)x.SubItems[ColumnIndex].Tag).CompareTo(y.SubItems[ColumnIndex].Tag));
                }
                catch
                {
                }
            }
            return(SortMultiplier * string.Compare(x.SubItems[ColumnIndex].Text, y.SubItems[ColumnIndex].Text));
        }
Пример #3
0
        ///<summary>
        ///Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        ///</summary>
        ///
        ///<returns>
        ///Value Condition Less than zerox is less than y.Zerox equals y.Greater than zerox is greater than y.
        ///</returns>
        ///
        ///<param name="y">The second object to compare.</param>
        ///<param name="x">The first object to compare.</param>
        public virtual int Compare(TreeDataGridViewRow x, TreeDataGridViewRow y)
        {
            if (x.Cells[ColumnIndex].Tag == null || y.Cells[ColumnIndex].Tag == null)
            {
                string xValueString = x.Cells[ColumnIndex].Value != null ? x.Cells[ColumnIndex].Value.ToString() : "";
                string yValueString = y.Cells[ColumnIndex].Value != null ? y.Cells[ColumnIndex].Value.ToString() : "";
                return(SortMultiplier * string.Compare(xValueString, yValueString));
            }
            if (x.Cells[ColumnIndex].Tag is AtaChapter && y.Cells[ColumnIndex].Tag is AtaChapter)
            {
                string xValueString = x.Cells[ColumnIndex].Value != null ? x.Cells[ColumnIndex].Value.ToString() : "";
                string yValueString = y.Cells[ColumnIndex].Value != null ? y.Cells[ColumnIndex].Value.ToString() : "";
                return(ComparerMethods.ATAComparer(xValueString, yValueString) * SortMultiplier);
            }
            if (x.Cells[ColumnIndex].Tag is DirectiveStatus && y.Cells[ColumnIndex].Tag is DirectiveStatus)
            {
                return(ComparerMethods.DirectiveStatusComparer((DirectiveStatus)x.Cells[ColumnIndex].Tag,
                                                               (DirectiveStatus)y.Cells[ColumnIndex].Tag) *
                       SortMultiplier);
            }
            if (x.Cells[ColumnIndex].Tag is DateTime && y.Cells[ColumnIndex].Tag is DateTime)
            {
                DateTime xValue = (DateTime)x.Cells[ColumnIndex].Tag;
                DateTime yValue = (DateTime)y.Cells[ColumnIndex].Tag;
                return(SortMultiplier * DateTime.Compare(yValue, xValue));
            }
            if (x.Cells[ColumnIndex].Tag is string && y.Cells[ColumnIndex].Tag is string)
            {
                return(SortMultiplier * string.Compare((string)x.Cells[ColumnIndex].Tag, (string)y.Cells[ColumnIndex].Tag));
            }
            if (x.Cells[ColumnIndex].Tag is int && y.Cells[ColumnIndex].Tag is int)
            {
                int xValue = (int)x.Cells[ColumnIndex].Tag;
                int yValue = (int)y.Cells[ColumnIndex].Tag;
                return(SortMultiplier * (yValue - xValue));
            }
            if (x.Cells[ColumnIndex].Tag is double && y.Cells[ColumnIndex].Tag is double)
            {
                double xValue = (double)x.Cells[ColumnIndex].Tag;
                double yValue = (double)y.Cells[ColumnIndex].Tag;
                return(SortMultiplier * (int)(yValue - xValue));
            }
            if (x.Cells[ColumnIndex].Tag as IComparable != null && (x.Cells[ColumnIndex].Tag.GetType().Equals(y.Cells[ColumnIndex].Tag.GetType())))
            {
                return(SortMultiplier * ((IComparable)x.Cells[ColumnIndex].Tag).CompareTo(y.Cells[ColumnIndex].Tag));
            }
            string s1 = x.Cells[ColumnIndex].Value != null ? x.Cells[ColumnIndex].Value.ToString() : "";
            string s2 = y.Cells[ColumnIndex].Value != null ? y.Cells[ColumnIndex].Value.ToString() : "";

            return(SortMultiplier * string.Compare(s1, s2));
        }
Пример #4
0
        ///<summary>
        ///Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        ///</summary>
        ///
        ///<returns>
        ///Value Condition Less than zerox is less than y.Zerox equals y.Greater than zerox is greater than y.
        ///</returns>
        ///
        ///<param name="y">The second object to compare.</param>
        ///<param name="x">The first object to compare.</param>
        public override int Compare(GridViewRowInfo x, GridViewRowInfo y)
        {
            var first  = ((CustomCell)x.Cells[ColumnIndex].Tag);
            var second = ((CustomCell)y.Cells[ColumnIndex].Tag);

            if (ColumnIndex == 0)
            {
                Match xMatch = Regex.Match(first.Text, Pattern);
                Match yMatch = Regex.Match(second.Text, Pattern);
                if (xMatch.Success && yMatch.Success)
                {
                    int xYear;
                    int xNumber1;
                    int xNumber2;
                    int.TryParse(xMatch.Groups["Year"].Value, out xYear);
                    int.TryParse(xMatch.Groups["Number1"].Value, out xNumber1);
                    int.TryParse(xMatch.Groups["Number2"].Value, out xNumber2);
                    string xParagraphLetter = "";
                    if (xMatch.Groups["ParagraphLetter"].Success)
                    {
                        xParagraphLetter = xMatch.Groups["ParagraphLetter"].Value;
                    }
                    int xParagraphNumber = 0;
                    if (xMatch.Groups["ParagraphNumber"].Success)
                    {
                        xParagraphNumber = int.Parse(xMatch.Groups["ParagraphNumber"].Value);
                    }
                    int yYear;
                    int yNumber1;
                    int yNumber2;
                    int.TryParse(yMatch.Groups["Year"].Value, out yYear);
                    int.TryParse(yMatch.Groups["Number1"].Value, out yNumber1);
                    int.TryParse(yMatch.Groups["Number2"].Value, out yNumber2);
                    string yParagraphLetter = "";
                    if (yMatch.Groups["ParagraphLetter"].Success)
                    {
                        yParagraphLetter = yMatch.Groups["ParagraphLetter"].Value;
                    }
                    int yParagraphNumber = 0;
                    if (yMatch.Groups["ParagraphNumber"].Success)
                    {
                        yParagraphNumber = int.Parse(yMatch.Groups["ParagraphNumber"].Value);
                    }

                    if (xYear < 100)
                    {
                        xYear += 1900;
                    }
                    if (yYear < 100)
                    {
                        yYear += 1900;
                    }
                    return((xYear == yYear) ? (xNumber1 == yNumber1) ? (xNumber2 == yNumber2) ? (xParagraphLetter == yParagraphLetter) ? (xParagraphNumber == yParagraphNumber) ? 0 : (xParagraphNumber - yParagraphNumber) : string.Compare(xParagraphLetter, yParagraphLetter) : SortMultiplier * (xNumber2 - yNumber2) : SortMultiplier * (xNumber1 - yNumber1) : SortMultiplier * (xYear - yYear));
                }
                if (xMatch.Success)
                {
                    return(-1);
                }
                if (yMatch.Success)
                {
                    return(1);
                }
                return(SortMultiplier * string.Compare(first.Text, second.Text));
            }



            if (first.Tag == null || second.Tag == null)
            {
                return(SortMultiplier * string.Compare(first.Text, second.Text));
            }
            if (first.Tag is AtaChapter && second.Tag is AtaChapter)
            {
                return(ComparerMethods.ATAComparer(first.Text, second.Text) *
                       SortMultiplier);
            }
            if (first.Tag is DirectiveStatus && second.Tag is DirectiveStatus)
            {
                return(ComparerMethods.DirectiveStatusComparer((DirectiveStatus)first.Tag,
                                                               (DirectiveStatus)second.Tag) *
                       SortMultiplier);
            }
            if (first.Tag is DateTime && second.Tag is DateTime)
            {
                DateTime xValue = (DateTime)first.Tag;
                DateTime yValue = (DateTime)second.Tag;
                return(SortMultiplier * DateTime.Compare(yValue, xValue));
            }
            if (first.Tag is string && second.Tag is string)
            {
                int i, j;
                if (int.TryParse(first.Text, out i) && int.TryParse(second.Text, out j))
                {
                    return(SortMultiplier * (i - j));
                }

                return(SortMultiplier * string.Compare(first.Text, second.Text));
            }
            if (first.Tag is int && second.Tag is int)
            {
                int xValue = (int)first.Tag;
                int yValue = (int)second.Tag;
                return(SortMultiplier * (yValue - xValue));
            }
            if (first.Tag is double && second.Tag is double)
            {
                double xValue = (double)first.Tag;
                double yValue = (double)second.Tag;
                return(SortMultiplier * (int)(yValue - xValue));
            }
            if (first.Tag as IComparable != null && (first.Tag.GetType().Equals(second.Tag.GetType())))
            {
                try
                {
                    return(SortMultiplier * ((IComparable)first.Tag).CompareTo(second.Tag));
                }
                catch
                {
                }
            }
            return(SortMultiplier * string.Compare(first.Text, second.Text));



            return(base.Compare(x, y));
        }