using System; namespace GZTW.AyaNova.BLL { /// /// A simple lightweight name/value item /// that can be inserted into a grid /// /// [Serializable] public class GridNameValueCellItem : IComparable //Added:03-Aug-2006 to implement icomparable { private Guid mValue; private string mDisplay; private RootObjectTypes mRootObjectType; /// /// /// /// /// /// public GridNameValueCellItem(Guid Value, string Display, RootObjectTypes RootObjectType) { mValue=Value; mDisplay=Display; mRootObjectType=RootObjectType; } /// /// /// /// public override int GetHashCode() { return this.Display.GetHashCode(); } /// /// /// /// /// public override bool Equals(object obj) { //Some of the grid sort and filter methods //are calling this with a string value for comparison //so handle it here this way if(obj.GetType()==typeof(System.String)) return (this.Display==obj.ToString()); if(obj.GetType()==typeof(System.Guid)) return (this.Value==(Guid)obj); if(obj.GetType()==typeof(GridNameValueCellItem)) { GridNameValueCellItem i=(GridNameValueCellItem)obj; return(i.Display==this.Display); } //It's not a type we can deal with here so it's not equal return false; } //Added:03-Aug-2006 to allow proper filtering in grid //when filtering workorder numbers versus filtering other text which //was just filtering alpha all the time which in turn was causing trouble in the grid picking //a second or third filter from a drop down because inside the grid it thought there were no //matching records to choose from. //Implement icomparable /// /// /// /// /// public int CompareTo(object obj) { if(!(obj is GridNameValueCellItem)) throw new ArgumentException("Object is not a GridNameValueCellItem."); GridNameValueCellItem compare = (GridNameValueCellItem)obj; //if comparing items based definitely on an integer value //like workorders or quotes or pm's then we need to case to an int //and compare as int if (compare.RootObjectType == RootObjectTypes.Workorder || compare.RootObjectType == RootObjectTypes.WorkorderQuote || compare.RootObjectType == RootObjectTypes.WorkorderService || compare.RootObjectType == RootObjectTypes.WorkorderPreventiveMaintenance || compare.RootObjectType == RootObjectTypes.PartInventoryAdjustment) { try { //If this fails then they are likey unparseable strings //so compare as strings in the catch block int dy = int.Parse(compare.Display); int dx = int.Parse(this.Display); //compare if (dx < dy) return -1; if (dx > dy) return 1; //must be equal return 0; } catch { return this.Display.CompareTo(compare.Display); } } //else compare as strings return this.Display.CompareTo(compare.Display); } //necessary to give the grid something to display /// /// /// /// public override string ToString() { return mDisplay; } //Public properties used to fetch value back later on when //retrieving selection from grid /// /// UI display value of item /// public string Display { get { return mDisplay; } } /// /// Guid value of item /// public Guid Value { get { return mValue; } } /// /// object type of item /// public RootObjectTypes RootObjectType { get { return mRootObjectType; } } } }