164 lines
4.6 KiB
C#
164 lines
4.6 KiB
C#
using System;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// A simple lightweight name/value item
|
|
/// that can be inserted into a grid
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class GridNameValueCellItem : IComparable //Added:03-Aug-2006 to implement icomparable
|
|
{
|
|
private Guid mValue;
|
|
private string mDisplay;
|
|
private RootObjectTypes mRootObjectType;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="Value"></param>
|
|
/// <param name="Display"></param>
|
|
/// <param name="RootObjectType"></param>
|
|
public GridNameValueCellItem(Guid Value, string Display, RootObjectTypes RootObjectType)
|
|
{
|
|
mValue=Value;
|
|
mDisplay=Display;
|
|
mRootObjectType=RootObjectType;
|
|
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return this.Display.GetHashCode();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
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
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
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
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return mDisplay;
|
|
}
|
|
|
|
//Public properties used to fetch value back later on when
|
|
//retrieving selection from grid
|
|
/// <summary>
|
|
/// UI display value of item
|
|
/// </summary>
|
|
public string Display
|
|
{
|
|
get
|
|
{
|
|
return mDisplay;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Guid value of item
|
|
/// </summary>
|
|
public Guid Value
|
|
{
|
|
get
|
|
{
|
|
return mValue;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <see cref="RootObjectTypes"/> object type of item
|
|
/// </summary>
|
|
public RootObjectTypes RootObjectType
|
|
{
|
|
get
|
|
{
|
|
return mRootObjectType;
|
|
}
|
|
}
|
|
}
|
|
}
|