SafeDispatch/Safedispatch_4_0/Sort.cs
2024-02-22 18:43:59 +02:00

153 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using SafeMobileLib;
namespace Safedispatch_4_0
{
public enum SortDirection
{
Ascending,
Descending
}
public class VehicleComparer : IComparer
{
private SortDirection m_direction = SortDirection.Ascending;
public VehicleComparer() : base() { }
public VehicleComparer(SortDirection direction)
{
this.m_direction = direction;
}
int IComparer.Compare(object x, object y)
{
SMposition positionX = (SMposition)x;
SMposition positionY = (SMposition)y;
if (positionX == null && positionY == null)
{
return 0;
}
else if (positionX == null && positionY != null)
{
return (this.m_direction == SortDirection.Ascending) ? -1 : 1;
}
else if (positionX != null && positionY == null)
{
return (this.m_direction == SortDirection.Ascending) ? 1 : -1;
}
else
{
return (this.m_direction == SortDirection.Ascending) ?
positionX.m_time.CompareTo(positionY.m_time) :
positionY.m_time.CompareTo(positionX.m_time);
}
}
}
public class VehicleNameComparer : IComparer
{
private SortDirection m_direction = SortDirection.Ascending;
public VehicleNameComparer() : base() { }
public VehicleNameComparer(SortDirection direction)
{
this.m_direction = direction;
}
int IComparer.Compare(object x, object y)
{
String positionX = (String)x;
String positionY = (String)y;
if (positionX == null && positionY == null)
{
return 0;
}
else if (positionX == null && positionY != null)
{
return (this.m_direction == SortDirection.Ascending) ? -1 : 1;
}
else if (positionX != null && positionY == null)
{
return (this.m_direction == SortDirection.Ascending) ? 1 : -1;
}
else
{
return (this.m_direction == SortDirection.Ascending) ? positionX.CompareTo(positionY) : positionY.CompareTo(positionX);
}
}
}
public class PlaceComparer : IComparer
{
public PlaceComparer() : base() { }
int IComparer.Compare(object x, object y)
{
Place X = x as Place;
Place Y = y as Place;
return String.Compare(X.type, Y.type);
}
}
public class DefineSMSComparer : IComparer
{
public DefineSMSComparer() : base() { }
int IComparer.Compare(object x, object y)
{
Zone_type X = x as Zone_type;
Zone_type Y = y as Zone_type;
return String.Compare(X.name,Y.name);
}
}
public class ZoneClassComparer : IComparer
{
public ZoneClassComparer() : base() { }
int IComparer.Compare(object x, object y)
{
ZoneClass X = x as ZoneClass;
ZoneClass Y = y as ZoneClass;
return String.Compare(X.name, Y.name);
}
}
public class VehandIDComparer : IComparer
{
public VehandIDComparer() : base() { }
int IComparer.Compare(object x, object y)
{
VehandID X = x as VehandID;
VehandID Y = y as VehandID;
return String.Compare(X.Name, Y.Name);
}
}
public class UserComparer : IComparer
{
public UserComparer() : base() { }
int IComparer.Compare(object x, object y)
{
User X = x as User;
User Y = y as User;
return String.Compare(X.UserName, Y.UserName);
}
}
}