///<summary>IComparable.CompareTo implementation. This is used to order benefit lists as well as to group benefits if the type is essentially equal. It doesn't compare values such as percentages or amounts. It only compares types.</summary> public int CompareTo(object obj) { if (!(obj is Benefit)) { throw new ArgumentException("object is not a Benefit"); } Benefit ben = (Benefit)obj; //first by fam if (CoverageLevel != ben.CoverageLevel) { return(CoverageLevel.CompareTo(ben.CoverageLevel)); } //then by type if (BenefitType != ben.BenefitType) //if types are different { return(BenefitType.CompareTo(ben.BenefitType)); } //types are the same, so check covCat. This is a loose comparison, ignored if either is 0. if (CovCatNum != 0 && ben.CovCatNum != 0 && //if both covcats have values CovCatNum != ben.CovCatNum) //and they are different //return CovCats.GetOrderShort(CovCatNum).CompareTo(CovCats.GetOrderShort(ben.CovCatNum)); //this line was changed because we really do need to know if they have different covcats. { return(CovCatB.GetOrderLong(CovCatNum).CompareTo(CovCatB.GetOrderLong(ben.CovCatNum))); } //ProcCode //THIS IS WRONG! NEED TO COMPARE THE PROCCODES, NOT THE CODENUMS. if (CodeNum != ben.CodeNum) { return(CodeNum.CompareTo(ben.CodeNum)); } //TimePeriod-ServiceYear and CalendarYear are treated as the same. //if either are not serviceYear or CalendarYear if ((TimePeriod != BenefitTimePeriod.CalendarYear && TimePeriod != BenefitTimePeriod.ServiceYear) || (ben.TimePeriod != BenefitTimePeriod.CalendarYear && ben.TimePeriod != BenefitTimePeriod.ServiceYear)) { return(TimePeriod.CompareTo(ben.TimePeriod)); } //QuantityQualifier if (QuantityQualifier != ben.QuantityQualifier) //if different { return(QuantityQualifier.CompareTo(ben.QuantityQualifier)); } //always different if plan vs. pat override if (PatPlanNum == 0 && ben.PatPlanNum != 0) { return(-1); } if (PlanNum == 0 && ben.PlanNum != 0) { return(1); } //Last resort. Can't find any significant differencesin the type, so: return(0); //then values are the same. }
///<summary>IComparable.CompareTo implementation. This is used to order benefit lists as well as to group benefits if the type is essentially equal. It doesn't compare values such as percentages or amounts. It only compares types.</summary> public int CompareTo(object obj) { if (!(obj is Benefit)) { throw new ArgumentException("object is not a Benefit"); } Benefit ben = (Benefit)obj; //first by fam if (CoverageLevel != ben.CoverageLevel) { return(CoverageLevel.CompareTo(ben.CoverageLevel)); } //then by type if (BenefitType != ben.BenefitType) //if types are different { return(BenefitType.CompareTo(ben.BenefitType)); } //types are the same, so check covCat. This is a loose comparison, ignored if either is 0. if (CovCatNum != 0 && ben.CovCatNum != 0 && //if both covcats have values CovCatNum != ben.CovCatNum) //and they are different //return CovCats.GetOrderShort(CovCatNum).CompareTo(CovCats.GetOrderShort(ben.CovCatNum)); //this line was changed because we really do need to know if they have different covcats. { return(CovCats.GetFindIndex(x => x.CovCatNum == CovCatNum).CompareTo(CovCats.GetFindIndex(x => x.CovCatNum == ben.CovCatNum))); } //ProcCode if (CodeNum != ben.CodeNum) { if (CovCatNum != 0 && CovCatNum == ben.CovCatNum) //Both benefits are for same custom frequency group or the exam group. { return(ProcedureCodes.GetStringProcCode(CodeNum).CompareTo(ProcedureCodes.GetStringProcCode(ben.CodeNum))); } int frequencyGroup1 = GetFrequencyGroupNum(); int frequencyGroup2 = ben.GetFrequencyGroupNum(); if (frequencyGroup1 == frequencyGroup2) { return(ProcedureCodes.GetStringProcCode(CodeNum) .CompareTo(ProcedureCodes.GetStringProcCode(ben.CodeNum))); } return(frequencyGroup1.CompareTo(frequencyGroup2)); } //TimePeriod-ServiceYear and CalendarYear are treated as the same. //if either are not serviceYear or CalendarYear List <BenefitTimePeriod> listTimePeriods = new List <BenefitTimePeriod>() { BenefitTimePeriod.CalendarYear, BenefitTimePeriod.ServiceYear }; if ((!TimePeriod.In(listTimePeriods) && !ben.TimePeriod.In(listTimePeriods) && TimePeriod != ben.TimePeriod) || (TimePeriod.In(listTimePeriods) != ben.TimePeriod.In(listTimePeriods))) { return(TimePeriod.CompareTo(ben.TimePeriod)); } //QuantityQualifier if (QuantityQualifier != ben.QuantityQualifier) //if different { return(QuantityQualifier.CompareTo(ben.QuantityQualifier)); } //always different if plan vs. pat override if (PatPlanNum == 0 && ben.PatPlanNum != 0) { return(-1); } if (PlanNum == 0 && ben.PlanNum != 0) { return(1); } //Last resort. Can't find any significant differences in the type, so: return(0); //then values are the same. }