CategoriesCollection.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:1k
- using System;
- using System.Collections;
- namespace qminoa.BLL.PM
- {
- public class CategoriesCollection : ArrayList
- {
- public enum CategoryFields
- {
- Abbreviation,
- Duration,
- InitValue,
- Name
- }
- public void Sort(CategoryFields sortField, bool isAscending)
- {
- switch (sortField)
- {
- case CategoryFields.Name:
- base.Sort(new NameComparer());
- break;
- case CategoryFields.Abbreviation:
- base.Sort(new AbbreviationComparer());
- break;
- case CategoryFields.Duration:
- base.Sort(new DurationComparer());
- break;
- }
- if (!isAscending) base.Reverse();
- }
- private sealed class NameComparer : IComparer
- {
- public int Compare(object x, object y)
- {
- Category first = (Category) x;
- Category second = (Category) y;
- return first.Name.CompareTo(second.Name);
- }
- }
- private sealed class AbbreviationComparer : IComparer
- {
- public int Compare(object x, object y)
- {
- Category first = (Category) x;
- Category second = (Category) y;
- return first.Abbreviation.CompareTo(second.Abbreviation);
- }
- }
- private sealed class DurationComparer : IComparer
- {
- public int Compare(object x, object y)
- {
- Category first = (Category) x;
- Category second = (Category) y;
- return first.EstDuration.CompareTo(second.EstDuration);
- }
- }
- }
- }