2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Contracts
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public enum BillItemType
|
|
|
|
|
{
|
|
|
|
|
Product,
|
|
|
|
|
Kot
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
public class BillItemKey
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private BillItemKey(int productID, int kotID, BillItemType billItemType)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (kotID < 0)
|
|
|
|
|
throw new ArgumentException("KotID Cannot be Negative");
|
|
|
|
|
if (productID < 0)
|
|
|
|
|
throw new ArgumentException("ProductID Cannot be Negative");
|
|
|
|
|
BillItemType = billItemType;
|
|
|
|
|
ProductID = productID;
|
|
|
|
|
KotID = kotID;
|
|
|
|
|
}
|
|
|
|
|
public BillItemKey(int kotID)
|
|
|
|
|
: this(0, kotID, BillItemType.Kot)
|
|
|
|
|
{ }
|
|
|
|
|
public BillItemKey(int productID, int kotID)
|
|
|
|
|
: this(productID, kotID, BillItemType.Product)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
private int _productID;
|
|
|
|
|
public int ProductID
|
|
|
|
|
{
|
|
|
|
|
get { return BillItemType == BillItemType.Product ? _productID : 0; }
|
|
|
|
|
private set { _productID = BillItemType == BillItemType.Product ? value : 0; }
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public int KotID { get; private set; }
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public BillItemType BillItemType { get; private set; }
|
2010-03-02 17:56:21 +00:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return BillItemType == BillItemType.Product ?
|
|
|
|
|
ProductID.GetHashCode() ^ KotID.GetHashCode() ^ BillItemType.GetHashCode()
|
|
|
|
|
: KotID.GetHashCode() ^ BillItemType.GetHashCode(); ;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is BillItemKey)
|
|
|
|
|
return (this == (BillItemKey)obj);
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
return string.Format("{0} - {1}", ProductID, KotID);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(BillItemKey a, BillItemKey b)
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (object.ReferenceEquals(null, a))
|
|
|
|
|
return object.ReferenceEquals(null, b);
|
2011-01-31 20:33:22 +00:00
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
if (!(a is BillItemKey))
|
|
|
|
|
return false;
|
|
|
|
|
if (!(b is BillItemKey))
|
|
|
|
|
return false;
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (a.BillItemType != b.BillItemType)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return a.BillItemType == BillItemType.Product ?
|
|
|
|
|
a.ProductID == b.ProductID && a.KotID == b.KotID && a.BillItemType == b.BillItemType
|
|
|
|
|
: a.KotID == b.KotID && a.BillItemType == b.BillItemType;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
public static bool operator !=(BillItemKey a, BillItemKey b)
|
|
|
|
|
{
|
|
|
|
|
return !(a == b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|