Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/TaxCodeList.cs
2018-06-29 19:47:36 +00:00

329 lines
7.5 KiB
C#

///////////////////////////////////////////////////////////
// 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
{
/// <summary>
/// Lightweight read only list of <see cref="TaxCode"/> objects for selection in UI
///
/// </summary>
[Serializable]
public class TaxCodeList : ReadOnlyCollectionBase
{
#pragma warning disable 1591
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct TaxCodeListInfo
{
internal Guid mID;
/// <summary>
/// Decimal amount for this tax
/// </summary>
internal decimal mTaxA;
/// <summary>
/// decimal amount for this tax
/// </summary>
internal decimal mTaxB;
/// <summary>
/// default is false
/// True indicates that where this is applied is tax exempt
/// </summary>
internal bool mTaxAExempt;
/// <summary>
/// default is false
/// True indicates that where this is applied is tax exempt
/// </summary>
internal bool mTaxBExempt;
/// <summary>
/// Default is false
/// If true, than the TaxB amount is determined from the total of itemcost + TaxA
/// amount X TaxB
/// </summary>
internal bool mTaxOnTax;
internal string mName;
//case 360
internal bool mActive;
/// <summary>
/// Get internal id number Read only property because it's set internally, not
/// externally
/// </summary>
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;
}
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(TaxCodeListInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end TaxCodeListInfo
#endregion
#pragma warning restore 1591
#region Constructor
/// <summary>
///
/// </summary>
protected TaxCodeList()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
/// <summary>
/// Get item by index
/// </summary>
/// <param name="Item"></param>
public TaxCodeListInfo this[int Item]
{
get
{
return (TaxCodeListInfo) List[Item];
}
}
/// <summary>
/// Returns item that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
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
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(TaxCodeListInfo obj)
{
foreach (TaxCodeListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// Get all TaxCode (unfiltered as it's not used in an interface but for calcs)
/// </summary>
/// <returns></returns>
public static TaxCodeList GetList()
{
return (TaxCodeList) DataPortal.Fetch(new Criteria(null));
}
/// <summary>
/// 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)
/// </summary>
/// <param name="mustHaveList"></param>
/// <returns></returns>
public static TaxCodeList GetList(System.Collections.Generic.List<Guid> mustHaveList)
{
return (TaxCodeList)DataPortal.Fetch(new Criteria(mustHaveList));
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
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
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
//case 360 added crit
public System.Collections.Generic.List<Guid> MustHaveList;
public Criteria(System.Collections.Generic.List<Guid> _MustHaveList)
{
MustHaveList = _MustHaveList;
}
}
#endregion
}//end TaxCodeList
}//end namespace GZTW.AyaNova.BLL