617 lines
17 KiB
C#
617 lines
17 KiB
C#
///////////////////////////////////////////////////////////
|
|
// VendorList.cs
|
|
// Implementation of Class VendorList
|
|
// CSLA type: Read only collection
|
|
// Created on: 07-Jun-2004 8:41:14 AM
|
|
// Object design: Joyce
|
|
// Coded: Sept. 23rd 2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
/// <summary>
|
|
/// Read only collection of <see cref="VendorList.VendorListInfo"/> objects representing <see cref="Vendor"/> objects.
|
|
/// Used in UI in grids and in summary reports.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class VendorList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct VendorListInfo
|
|
{
|
|
|
|
|
|
|
|
//internal Guid mID;
|
|
|
|
internal GridNameValueCellItem mVendor;
|
|
|
|
//internal string mVendorName;
|
|
internal VendorTypes mVendorType;//Vendor.Label.VendorType
|
|
//CONTACT FIELDS
|
|
internal string mContact;
|
|
internal string mEmail;
|
|
internal string mPhone1;
|
|
internal string mPhone2;
|
|
internal string mPhone3;
|
|
internal string mPhone4;
|
|
internal string mPhone5;
|
|
|
|
|
|
|
|
internal string mDeliveryAddress;
|
|
internal string mCity;
|
|
internal string mStateProv;
|
|
internal string mCountry;
|
|
internal string mPostal;
|
|
internal bool mActive;
|
|
internal string mAccountNumber;
|
|
internal string mWebAddress;
|
|
internal string mLatitude;
|
|
internal string mLongitude;
|
|
internal string mCountryCode;
|
|
|
|
|
|
|
|
[SqlColumnNameAttribute("aVendor.aName",
|
|
"AVendor.AID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]
|
|
public GridNameValueCellItem LT_Vendor_Label_ID
|
|
{
|
|
get
|
|
{
|
|
return mVendor;
|
|
}
|
|
}
|
|
|
|
//Case 796
|
|
[SqlColumnNameAttribute("aVendor.aName",
|
|
"AVendor.AID"),
|
|
Display(DisplayType.Hidden, RootObjectType = RootObjectTypes.Vendor)]
|
|
public GridNameValueCellItem LT_O_Vendor
|
|
{
|
|
get
|
|
{
|
|
return mVendor;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.ListVendorTypes)]
|
|
public VendorTypes LT_Vendor_Label_VendorType
|
|
{
|
|
get
|
|
{
|
|
return mVendorType;
|
|
}
|
|
}
|
|
|
|
//CONTACT FIELDS
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Contact
|
|
{ get { return mContact; } }
|
|
|
|
[Display(DisplayType.URL_Email)]
|
|
public string LT_Vendor_Label_Email
|
|
{ get { return mEmail; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Phone1
|
|
{ get { return mPhone1; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Phone2
|
|
{ get { return mPhone2; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Phone3
|
|
{ get { return mPhone3; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Phone4
|
|
{ get { return mPhone4; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_Phone5
|
|
{ get { return mPhone5; } }
|
|
|
|
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Vendor_Label_AccountNumber
|
|
{
|
|
get
|
|
{
|
|
return mAccountNumber;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_DeliveryAddress
|
|
{
|
|
get
|
|
{
|
|
return mDeliveryAddress;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_City
|
|
{
|
|
get
|
|
{
|
|
return mCity;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_StateProv
|
|
{
|
|
get
|
|
{
|
|
return mStateProv;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_Country
|
|
{
|
|
get
|
|
{
|
|
return mCountry;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_Postal
|
|
{
|
|
get
|
|
{
|
|
return mPostal;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_Vendor_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.URL_Web)]
|
|
public string LT_Vendor_Label_WebAddress
|
|
{
|
|
get
|
|
{
|
|
return mWebAddress;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.GeoCoordinate)]
|
|
public string LT_Address_Label_Latitude
|
|
{
|
|
get
|
|
{
|
|
return mLatitude;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.GeoCoordinate)]
|
|
public string LT_Address_Label_Longitude
|
|
{
|
|
get
|
|
{
|
|
return mLongitude;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Address_Label_CountryCode
|
|
{
|
|
get
|
|
{
|
|
return mCountryCode;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(VendorListInfo obj)
|
|
{
|
|
return this.mVendor.Value.Equals(obj.mVendor.Value);
|
|
}
|
|
|
|
}//end VendorListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected VendorList()
|
|
{
|
|
// 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 VendorListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (VendorListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (VendorListInfo child in List)
|
|
{
|
|
if(child.mVendor.Value==ItemID) return child.ToString();
|
|
}
|
|
return "Missing: "+ItemID.ToString();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(VendorListInfo obj)
|
|
{
|
|
foreach (VendorListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Reporting and shared UI editor helpers
|
|
|
|
/// <summary>
|
|
/// Returns the report key which is a property of
|
|
/// reports used to link all reports that can be used
|
|
/// with a particular data source.
|
|
/// </summary>
|
|
public static string ReportKey
|
|
{
|
|
get
|
|
{
|
|
return "VendorList";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Detailed report key
|
|
/// which is used to determine which reports and objects
|
|
/// will be used for detailed reports
|
|
///
|
|
/// If empty string then indicates there is no detailed report object or reports
|
|
/// </summary>
|
|
public static string DetailedReportKey
|
|
{
|
|
get
|
|
{
|
|
return VendorListDetailed.ReportKey;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Base object that this list is reporting on
|
|
/// used by shared UI editor to instantiate new objects
|
|
/// when user selects new in UI elements that display this list
|
|
///
|
|
/// (I.E. when user clicks on new in a read only list grid, this is the object type created)
|
|
/// </summary>
|
|
public static RootObjectTypes BaseObjectType
|
|
{
|
|
get
|
|
{
|
|
return RootObjectTypes.Vendor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Locale key so that generic list editor
|
|
/// UI code knows what title to give the list in a
|
|
/// grid
|
|
/// </summary>
|
|
public string LocaleKey
|
|
{
|
|
get
|
|
{
|
|
return "Vendor.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Type of the struct used to store list records
|
|
/// Used to fetch the custom display attributes of the fields
|
|
/// contained within the record to modify the grid display accordingly
|
|
/// <see cref="DisplayAttribute"/>
|
|
/// </summary>
|
|
public static Type ListRecordType
|
|
{
|
|
get
|
|
{
|
|
return typeof(VendorListInfo);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Field that contains the ID of the objects
|
|
/// that are the basis of this list.
|
|
///
|
|
/// Used for compiling an ID list for reporting from user
|
|
/// selections in a grid.
|
|
/// </summary>
|
|
public static string IDField
|
|
{
|
|
get
|
|
{
|
|
return "LT_Vendor_Label_ID";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static VendorList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (VendorList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes an xml column list and where criteria
|
|
/// and returns a list filtered and sorted accordingly
|
|
/// </summary>
|
|
/// <param name="xmlCriteria">Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code</param>
|
|
/// <returns>collection of <see cref="VendorList.VendorListInfo"/> objects</returns>
|
|
public static VendorList GetListByCriteria(string xmlCriteria)
|
|
{
|
|
return (VendorList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="VendorID">ID of Vendor object</param>
|
|
/// <returns></returns>
|
|
public static VendorList GetListForSingleItem(Guid VendorID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(VendorID);
|
|
return GetListFromIDList(l);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>collection of <see cref="VendorList.VendorListInfo"/> objects</returns>
|
|
public static VendorList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new VendorList();
|
|
return (VendorList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static VendorList GetEmptyList()
|
|
{
|
|
return new VendorList();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = null;
|
|
if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" AND (aVendor.aID in (");
|
|
foreach (Guid gItem in crit.IDList)
|
|
{
|
|
sbIN.Append("'");
|
|
sbIN.Append("{");
|
|
sbIN.Append(gItem.ToString().ToUpperInvariant());
|
|
sbIN.Append("}");
|
|
sbIN.Append("',");
|
|
}
|
|
sbIN.Length = sbIN.Length - 1;
|
|
sbIN.Append(")) ");
|
|
|
|
dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT aVendor.aID, aVendor.aName, " +
|
|
"aVendor.AACTIVE, aVendor.aWebAddress, aVendor.aVendorType, aVendor.AACCOUNTNUMBER, " +
|
|
" AVENDOR.ACONTACT, AVENDOR.AEMAIL, AVENDOR.APHONE1, AVENDOR.APHONE2, AVENDOR.APHONE3, AVENDOR.APHONE4, AVENDOR.APHONE5, " +
|
|
|
|
"AADDRESS.aDeliveryAddress, AADDRESS.aCity, " +
|
|
"AADDRESS.aStateProv, AADDRESS.aCountry, " +
|
|
"AADDRESS.aPostal, AADDRESS.AADDRESSTYPE, " +
|
|
"AADDRESS.aLongitude, AADDRESS.aLatitude, AADDRESS.aCountryCode " +
|
|
"FROM " +
|
|
" AVENDOR " +
|
|
" LEFT OUTER JOIN AADDRESS ON (AVENDOR.AID=AADDRESS.AROOTOBJECTID) " +
|
|
"WHERE (AADDRESS.AADDRESSTYPE = 2 OR AADDRESS.AADDRESSTYPE IS NULL) " + sbIN.ToString() +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)
|
|
//************************************************************
|
|
);
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
|
|
//************************************************************
|
|
string q = "SELECT ~MAXRECS~ aVendor.aID, aVendor.aName, " +
|
|
"aVendor.AACTIVE, aVendor.aWebAddress, aVendor.aVendorType, aVendor.AACCOUNTNUMBER, " +
|
|
" AVENDOR.ACONTACT, AVENDOR.AEMAIL, AVENDOR.APHONE1, AVENDOR.APHONE2, AVENDOR.APHONE3, AVENDOR.APHONE4, AVENDOR.APHONE5, " +
|
|
|
|
"AADDRESS.aDeliveryAddress, AADDRESS.aCity, " +
|
|
"AADDRESS.aStateProv, AADDRESS.aCountry, " +
|
|
"AADDRESS.aPostal, AADDRESS.AADDRESSTYPE, " +
|
|
"AADDRESS.aLongitude, AADDRESS.aLatitude, AADDRESS.aCountryCode " +
|
|
"FROM " +
|
|
" AVENDOR " +
|
|
|
|
" LEFT OUTER JOIN AADDRESS ON (AVENDOR.AID=AADDRESS.AROOTOBJECTID) " +
|
|
"WHERE (AADDRESS.AADDRESSTYPE = 2 OR AADDRESS.AADDRESSTYPE IS NULL) \r\n" +
|
|
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, false) + "\r\n" +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
//************************************************************
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
dbCommandWrapper.AddInParameter("@aTrue",DbType.Boolean,true);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
VendorListInfo info=new VendorListInfo();
|
|
info.mVendor=new GridNameValueCellItem(
|
|
dr.GetGuid("aID"),
|
|
dr.GetString("aName"),
|
|
RootObjectTypes.Vendor);
|
|
|
|
|
|
info.mContact = dr.GetString("ACONTACT");
|
|
info.mEmail = dr.GetString("AEMAIL");
|
|
info.mPhone1 = dr.GetString("APHONE1");
|
|
info.mPhone2 = dr.GetString("APHONE2");
|
|
info.mPhone3 = dr.GetString("APHONE3");
|
|
info.mPhone4 = dr.GetString("APHONE4");
|
|
info.mPhone5 = dr.GetString("APHONE5");
|
|
|
|
|
|
info.mAccountNumber=dr.GetString("AACCOUNTNUMBER");
|
|
info.mDeliveryAddress=dr.GetString("aDeliveryAddress");
|
|
info.mCity=dr.GetString("aCity");
|
|
info.mStateProv=dr.GetString("aStateProv");
|
|
info.mCountry=dr.GetString("aCountry");
|
|
info.mPostal=dr.GetString("aPostal");
|
|
info.mActive=dr.GetBoolean("AACTIVE");
|
|
info.mVendorType=(VendorTypes)dr.GetInt16("aVendorType");
|
|
info.mWebAddress=dr.GetString("aWebAddress");
|
|
info.mLatitude=Address.LatitudeToString(dr.GetDecimal("aLatitude"));
|
|
info.mLongitude=Address.LongitudeToString(dr.GetDecimal("aLongitude"));
|
|
info.mCountryCode=dr.GetString("aCountryCode");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public List<Guid> IDList;
|
|
public string CriteriaXML;
|
|
public int MaxRecords;
|
|
public Criteria(string _CriteriaXML, List<Guid> _IDList, int _MaxRecords)
|
|
{
|
|
CriteriaXML = _CriteriaXML;
|
|
IDList = _IDList;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end VendorList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |