225 lines
7.5 KiB
C#
225 lines
7.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// GenericNVList.cs
|
|
// Implementation of Class GenericNVList
|
|
// CSLA type: Name-Value Lists
|
|
// Created on: 19 August 2004
|
|
// Object design: John
|
|
// Coded: John 19 August 2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using CSLA.Data;
|
|
using System.Runtime.Serialization;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.ComponentModel;
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Generic name / value list
|
|
/// </summary>
|
|
[Serializable, Browsable(false)]
|
|
public class GenericNVList : NameValueList
|
|
{//NVCHANGED
|
|
#region Constructors
|
|
//Prevent direct creation
|
|
|
|
private GenericNVList() {}
|
|
|
|
|
|
//Required because the base class (NameObjectCollectionBase) implements ISerializable
|
|
private GenericNVList(SerializationInfo info, StreamingContext context) : base(info, context) {}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get GenericNVList object
|
|
/// Retrieves a name value list from db
|
|
/// </summary>
|
|
/// <example>
|
|
/// This code shows a typical usage of the generic name value list
|
|
/// <code>
|
|
/// GenericNVList ls=GenericNVList.GetList("aWorkorderStatus","aID","aName",true,false);
|
|
/// foreach(DictionaryEntry d in ls.BindableList)
|
|
/// {
|
|
/// Guid gWorkorderStatusID=new Guid(d.Key.ToString());
|
|
/// string sWorkorderStatusName=d.Value.ToString();
|
|
/// //... populate a list box or other processing
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
public static GenericNVList GetList(string ObjectName,string IDColumn,
|
|
string ValueColumn, bool ValueIsGuid, bool ActiveOnly, bool Regional)//case 58
|
|
{
|
|
string sTempObjectName=ObjectName;
|
|
switch(ObjectName)
|
|
{
|
|
case "aVendor:Manufacturer":
|
|
sTempObjectName="Vendor";
|
|
break;
|
|
case "aVendor:Shipper":
|
|
sTempObjectName="Vendor";
|
|
break;
|
|
case "aVendor:SubContractor":
|
|
sTempObjectName="Vendor";
|
|
break;
|
|
case "aVendor:ThirdPartyRepair":
|
|
sTempObjectName="Vendor";
|
|
break;
|
|
case "aVendor:Wholesaler":
|
|
sTempObjectName="Vendor";
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
//if(AyaBizUtils.Right("Object."+AyaBizUtils.ToObjectName(sTempObjectName))>(int)SecurityLevelTypes.NoAccess)
|
|
return (GenericNVList) DataPortal.Fetch(new Criteria(ObjectName,IDColumn, ValueColumn,ValueIsGuid,ActiveOnly, Regional));
|
|
// else
|
|
// throw new System.Security.SecurityException(
|
|
// string.Format(
|
|
// LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
// LocalizedTextTable.GetLocalizedTextDirect("O." + AyaBizUtils.ToObjectName(sTempObjectName))));
|
|
//
|
|
}
|
|
|
|
private static string RegionAndActiveClause(bool ActiveOnly, string sTable, bool bRegional)
|
|
{
|
|
string q = "";
|
|
|
|
if(ActiveOnly)
|
|
q = " WHERE AACTIVE=1";
|
|
|
|
if (bRegional)
|
|
q = DBUtil.AddRegionFilter(q, sTable, "");
|
|
|
|
return q;
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
/// <summary>
|
|
/// Fetch name value list
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
switch(crit.TableName)
|
|
{
|
|
case "aVendor:Manufacturer":
|
|
this.SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aVendor WHERE aVendorType=" + ((int)VendorTypes.Manufacturer).ToString()+ " AND AACTIVE=1");
|
|
break;
|
|
case "aVendor:Shipper":
|
|
this.SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aVendor WHERE aVendorType=" + ((int)VendorTypes.Shipper).ToString()+ " AND AACTIVE=1");
|
|
break;
|
|
case "aVendor:SubContractor":
|
|
this.SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aVendor WHERE aVendorType=" + ((int)VendorTypes.SubContractor).ToString()+ " AND AACTIVE=1");
|
|
break;
|
|
case "aVendor:ThirdPartyRepair":
|
|
this.SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aVendor WHERE aVendorType=" + ((int)VendorTypes.ThirdPartyRepair).ToString()+ " AND AACTIVE=1");
|
|
break;
|
|
case "aVendor:Wholesaler":
|
|
this.SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aVendor WHERE aVendorType=" + ((int)VendorTypes.Wholesaler).ToString()+ " AND AACTIVE=1");
|
|
break;
|
|
case "aClient":
|
|
SQLFetchG(DBUtil.DB, "SELECT aID, aName FROM aClient " + RegionAndActiveClause(crit.ActiveOnly,"aClient", crit.Regional) );
|
|
break;
|
|
case "aUser":
|
|
SQLFetchG(DBUtil.DB, "SELECT aID, aName FROM aUser " + RegionAndActiveClause(crit.ActiveOnly, "aUser", crit.Regional));
|
|
break;
|
|
case "aHeadOffice":
|
|
SQLFetchG(DBUtil.DB, "SELECT aID, aName FROM aHeadOffice " + RegionAndActiveClause(crit.ActiveOnly, "aHeadOffice", crit.Regional));
|
|
break;
|
|
case "aContract":
|
|
SQLFetchG(DBUtil.DB, "SELECT aID, aName FROM aContract " + RegionAndActiveClause(crit.ActiveOnly, "aContract", crit.Regional));
|
|
break;
|
|
case "aRegion":
|
|
string q = "";
|
|
if (crit.Regional)
|
|
{
|
|
q=q+ (string)(
|
|
(User.CurrentUserRegionID != Region.DefaultRegionID) ?
|
|
" WHERE (aID IN ('{8236E8D1-CAB1-4797-9C34-93861954AE6A}','{" + User.CurrentUserRegionID.ToString().ToUpperInvariant() + "}')) "
|
|
: ""
|
|
);
|
|
}
|
|
if (crit.ActiveOnly)
|
|
{
|
|
if (q == "")
|
|
q = " WHERE AACTIVE=1";
|
|
else
|
|
q = q + " AND AACTIVE=1";
|
|
}
|
|
SQLFetchG(DBUtil.DB,"SELECT aID, aName FROM aRegion " + q );
|
|
break;
|
|
|
|
/*
|
|
* *Dispatch Zones
|
|
*Loan Items
|
|
*Projects
|
|
*Rates
|
|
*Report Templates
|
|
*Templates - workorders / quotes / pm
|
|
*Warehouses
|
|
* */
|
|
default:
|
|
{
|
|
|
|
//REgional ones:
|
|
|
|
if(crit.ValueIsGuid)
|
|
{
|
|
if(crit.ActiveOnly)
|
|
this.SimpleFetchGActiveOnly(DBUtil.DB,crit.TableName,crit.ValueColumn,crit.NameColumn);
|
|
else
|
|
this.SimpleFetchG(DBUtil.DB,crit.TableName,crit.ValueColumn ,crit.NameColumn);
|
|
}
|
|
else
|
|
this.SimpleFetch(DBUtil.DB,crit.TableName,crit.ValueColumn ,crit.NameColumn);
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
public string TableName;
|
|
public string NameColumn;
|
|
public string ValueColumn;
|
|
public bool ValueIsGuid;
|
|
public bool ActiveOnly;
|
|
public bool Regional;//case 58
|
|
public Criteria( string _TableName, string _NameColumn, string _ValueColumn, bool _ValueIsGuid, bool _ActiveOnly, bool _Regional)
|
|
{
|
|
if(_TableName=="User")
|
|
_TableName="aUser";
|
|
TableName=AyaBizUtils.ToDBName(_TableName);
|
|
NameColumn=AyaBizUtils.ToDBName(_NameColumn);
|
|
ValueColumn=AyaBizUtils.ToDBName(_ValueColumn);
|
|
ValueIsGuid=_ValueIsGuid;
|
|
ActiveOnly=_ActiveOnly;
|
|
Regional = _Regional;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end GenericNVList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |