///////////////////////////////////////////////////////////
// TaxCodeList.cs
// Implementation of Class TaxCodeList
// CSLA type: Read only collection
// Created on: 19-Nov-2004
// Object design: John
// Coded: 19-Nov-2004
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
using System.Collections.Generic;
namespace GZTW.AyaNova.BLL
{
///
/// Lightweight read only list of objects for selection in UI
///
///
[Serializable]
public class TaxCodeList : ReadOnlyCollectionBase
{
#pragma warning disable 1591
#region Data structure
///
/// Properties
///
[Serializable]
public struct TaxCodeListInfo
{
internal Guid mID;
///
/// Decimal amount for this tax
///
internal decimal mTaxA;
///
/// decimal amount for this tax
///
internal decimal mTaxB;
///
/// default is false
/// True indicates that where this is applied is tax exempt
///
internal bool mTaxAExempt;
///
/// default is false
/// True indicates that where this is applied is tax exempt
///
internal bool mTaxBExempt;
///
/// Default is false
/// If true, than the TaxB amount is determined from the total of itemcost + TaxA
/// amount X TaxB
///
internal bool mTaxOnTax;
internal string mName;
//case 360
internal bool mActive;
///
/// Get internal id number Read only property because it's set internally, not
/// externally
///
public Guid ID
{
get
{
return mID;
}
}
public decimal TaxA
{
get
{
return mTaxA;
}
}
public decimal TaxB
{
get
{
return mTaxB;
}
}
public bool TaxAExempt
{
get
{
return mTaxAExempt;
}
}
public bool TaxBExempt
{
get
{
return mTaxBExempt;
}
}
public bool TaxOnTax
{
get
{
return mTaxOnTax;
}
}
public string Name
{
get
{
return mName;
}
}
//Case 360
public bool Active
{
get
{
return mActive;
}
}
///
///
///
///
public bool Equals(TaxCodeListInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end TaxCodeListInfo
#endregion
#pragma warning restore 1591
#region Constructor
///
///
///
protected TaxCodeList()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
///
/// Get item by index
///
///
public TaxCodeListInfo this[int Item]
{
get
{
return (TaxCodeListInfo) List[Item];
}
}
///
/// Returns item that matches passed in itemid value
///
///
public TaxCodeListInfo this[Guid ItemID]
{
get
{
foreach (TaxCodeListInfo child in List)
{
if(child.mID==ItemID)
return child;
}
throw new ArgumentException("TaxCodeList: TaxCodeID not found:\r\n"+ItemID.ToString());
}
}
#endregion
#region contains
///
/// Check if item in collection
///
///
public bool Contains(TaxCodeListInfo obj)
{
foreach (TaxCodeListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
///
/// Get all TaxCode (unfiltered as it's not used in an interface but for calcs)
///
///
public static TaxCodeList GetList()
{
return (TaxCodeList) DataPortal.Fetch(new Criteria(null));
}
///
/// Get all active tax codes plus the inactive ones that are in the
/// mustHaveList which is a generic List of Guid's
/// (used for populating tax code lists in Workorder form UI, Workorder object
/// has a method for retrieving the mustHaveList which is all tax codes previously selected
/// on the work order)
///
///
///
public static TaxCodeList GetList(System.Collections.Generic.List mustHaveList)
{
return (TaxCodeList)DataPortal.Fetch(new Criteria(mustHaveList));
}
#endregion
#region DAL DATA ACCESS
///
///
protected override void DataPortal_Fetch(object Criteria)
{
SafeDataReader dr = null;
Criteria crit = (Criteria)Criteria;
try
{
dr=DBUtil.GetReaderFromSQLString(
//************************************************************
"SELECT * FROM aTaxCode"
//************************************************************
);
bool bActive = false;
while(dr.Read())
{
//*******************************************
//Case 360
bActive = dr.GetBoolean("AACTIVE");
//Logic:If it's not active then it might be skipped
//so if there is a must have list and it's not on it then skip it
//otherwise add it
if (!bActive && crit.MustHaveList != null && !crit.MustHaveList.Contains(dr.GetGuid("aID")))
continue;//Skip it...skip it good.
//It's active or it's not active but it's on the must have list or there is no must have list :)
TaxCodeListInfo info = new TaxCodeListInfo();
info.mID = dr.GetGuid("aID");
info.mName = dr.GetString("aName");
info.mTaxA = dr.GetDecimal("aTaxA");
info.mTaxB = dr.GetDecimal("aTaxB");
info.mTaxAExempt = dr.GetBoolean("aTaxAExempt");
info.mTaxBExempt = dr.GetBoolean("aTaxBExempt");
info.mTaxOnTax = dr.GetBoolean("aTaxOnTax");
//Case 360
info.mActive = dr.GetBoolean("AACTIVE");
InnerList.Add(info);
//*******************************************
}
}
finally
{
if(dr!=null) dr.Close();
}
}
#endregion
#region criteria
///
/// Criteria for identifying existing object
///
[Serializable]
private class Criteria
{
//case 360 added crit
public System.Collections.Generic.List MustHaveList;
public Criteria(System.Collections.Generic.List _MustHaveList)
{
MustHaveList = _MustHaveList;
}
}
#endregion
}//end TaxCodeList
}//end namespace GZTW.AyaNova.BLL