Files
2018-06-29 19:47:36 +00:00

630 lines
19 KiB
C#

///////////////////////////////////////////////////////////
// PurchaseOrderList.cs
// Implementation of Class PurchaseOrderList
// CSLA type: Read only collection
// Created on: 01-Nov-2004
// Object design: John
// Coded: 01-Nov-2004
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
using System.Collections.Generic;
namespace GZTW.AyaNova.BLL
{
#pragma warning disable 1591
/// <summary>
/// Read only list of <see cref="PurchaseOrderList.PurchaseOrderListInfo"/> objects representing <see cref="PurchaseOrder"/> objects. Used for reporting and grid lists.
/// </summary>
[Serializable]
public class PurchaseOrderList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct PurchaseOrderListInfo
{
internal GridNameValueCellItem mPONumber; //and ID
internal GridNameValueCellItem mClient; //and ID
internal GridNameValueCellItem mVendor; //and ID
internal GridNameValueCellItem mProject; //and ID //case 49
internal string mReferenceNumber;
//internal decimal mFreight;
//internal decimal mAdditionalCharges;
//internal bool mOrdered;
internal SmartDate mOrderedDate;
internal SmartDate mExpectedReceiveDate;
//internal DateTime mActualReceiveDate;
//internal bool mClosed;
internal DateTime mCreated;
internal DateTime mModified;
internal string mCreatorInitials;
internal string mModifierInitials;
internal PurchaseOrderStatus mStatus;
[SqlColumnNameAttribute("aPurchaseOrder.aPONumber",
"aPurchaseOrder.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.PurchaseOrder)]
public GridNameValueCellItem LT_PurchaseOrder_Label_PONumber
{
get
{
return mPONumber;
}
}
[SqlColumnNameAttribute("aVendor.aName",
"aVendor.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]
public GridNameValueCellItem LT_O_Vendor
{
get
{
return mVendor;
}
}
//case 49
[SqlColumnNameAttribute("aProject.aName",
"aProject.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Project)]
public GridNameValueCellItem LT_O_Project
{
get
{
return mProject;
}
}
[SqlColumnNameAttribute("aClient.aName",
"aClient.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client)]
public GridNameValueCellItem LT_PurchaseOrder_Label_DropShipToClientID
{
get
{
return mClient;
}
}
[Display(DisplayType.Text)]
public string LT_PurchaseOrder_Label_ReferenceNumber
{
get
{
return mReferenceNumber;
}
}
[Display(DisplayType.ListPurchaseOrderStatus)]
public PurchaseOrderStatus LT_PurchaseOrder_Label_Status
{
get
{
return mStatus;
}
}
[Display(DisplayType.DateTime)]
public object LT_PurchaseOrder_Label_OrderedDate
{
get
{
return mOrderedDate.DBValue;
}
}
[Display(DisplayType.DateTime)]
public object LT_PurchaseOrder_Label_ExpectedReceiveDate
{
get
{
return mExpectedReceiveDate.DBValue;
}
}
[SqlColumnNameAttribute("aPurchaseOrder.aCreated"), Display(DisplayType.DateTime)]
public DateTime LT_Common_Label_Created
{
get
{
return mCreated;
}
}
[SqlColumnNameAttribute("aPurchaseOrder.aModified"),Display(DisplayType.DateTime)]
public DateTime LT_Common_Label_Modified
{
get
{
return mModified;
}
}
[SqlColumnNameAttribute("aCreatorUser.aInitials"),Display(DisplayType.Text)]
public string LT_Common_Label_Creator
{
get
{
return mCreatorInitials;
}
}
[SqlColumnNameAttribute("aModifierUser.aInitials"), Display(DisplayType.Text)]
public string LT_Common_Label_Modifier
{
get
{
return mModifierInitials;
}
}
//case 867
internal string mCustom1;
internal string mCustom2;
internal string mCustom3;
internal string mCustom4;
internal string mCustom5;
internal string mCustom6;
internal string mCustom7;
internal string mCustom8;
internal string mCustom9;
internal string mCustom0;
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom1 { get { return mCustom1; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom2 { get { return mCustom2; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom3 { get { return mCustom3; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom4 { get { return mCustom4; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom5 { get { return mCustom5; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom6 { get { return mCustom6; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom7 { get { return mCustom7; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom8 { get { return mCustom8; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom9 { get { return mCustom9; } }
[Display(DisplayType.Text)]
public string LT_Part_Label_Custom0 { get { return mCustom0; } }
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(PurchaseOrderListInfo obj)
{
return this.mPONumber.Value.Equals(obj.mPONumber.Value);
}
}//end PurchaseOrderListInfo
#endregion
#region Constructor
protected PurchaseOrderList()
{
// 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 PurchaseOrderListInfo this[int Item]
{
get
{
return (PurchaseOrderListInfo) List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (PurchaseOrderListInfo child in List)
{
if(child.mPONumber.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(PurchaseOrderListInfo obj)
{
foreach (PurchaseOrderListInfo 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 "PurchaseOrderList";
}
}
/// <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 PurchaseOrderDetailedReportData.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.PurchaseOrder;
}
}
/// <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 "UI.Go.Inventory.PurchaseOrders";
}
}
/// <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(PurchaseOrderListInfo);
}
}
/// <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_PurchaseOrder_Label_PONumber";
}
}
/// <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 PurchaseOrderList Get(string Filter, int MaxRecords, List<Guid> IDList)
{
return (PurchaseOrderList)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>list of <see cref="PurchaseOrderList.PurchaseOrderListInfo"/> objects</returns>
public static PurchaseOrderList GetListByCriteria(string xmlCriteria)
{
return (PurchaseOrderList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
}
/// <summary>
/// Takes a single ID and returns a "list" of one object
/// </summary>
/// <param name="PurchaseOrderID">ID of PurchaseOrder object</param>
/// <returns></returns>
public static PurchaseOrderList GetListForSingleItem(Guid PurchaseOrderID)
{
//Case 556
List<Guid> l = new List<Guid>();
l.Add(PurchaseOrderID);
return GetListFromIDList(l);
}
/// <summary>
/// Get list by items indicated in IDList
/// </summary>
/// <param name="IDList">Generic list of Guid's</param>
/// <returns>list of <see cref="PurchaseOrderList.PurchaseOrderListInfo"/> objects</returns>
public static PurchaseOrderList GetListFromIDList(List<Guid> IDList)
{
//case 556
//Handle empty list
if (IDList.Count == 0)
return new PurchaseOrderList();
return (PurchaseOrderList)DataPortal.Fetch(new Criteria("", IDList, -1));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static PurchaseOrderList GetEmptyList()
{
return new PurchaseOrderList();
}
#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 cm = null;
//Base query
string q=
//************************************************************
"SELECT ~MAXRECS~ aPurchaseOrder.aID, aPurchaseOrder.aPONumber, aPurchaseOrder.aStatus, " +
"aClient.aID AS aClientID, aClient.aName AS " +
"aClientName, " +
"aPurchaseOrder.aReferenceNumber, " +
"aVendor.aID AS aVendorID, aVendor.aName AS aVendorName, " +
"aProject.aID AS aProjectID, aProject.aName AS aProjectName, " +//case 49
" aPurchaseOrder.aOrderedDate, " +
"aPurchaseOrder.aExpectedReceiveDate, " +
"aPurchaseOrder.aCreated AS aCreatedDate, " +
"aPurchaseOrder.aModified AS aModifiedDate, aCreatorUser.aInitials " +
"AS aCreatorInitials, aModifierUser.aInitials " +
"AS aModifierInitials, " +
//case 867
" aPurchaseOrder.aCustom1, " +
" aPurchaseOrder.aCustom2, aPurchaseOrder.aCustom3, " +
" aPurchaseOrder.aCustom4, " +
" aPurchaseOrder.aCustom5, aPurchaseOrder.aCustom6, " +
" aPurchaseOrder.aCustom7, aPurchaseOrder.aCustom8, " +
" aPurchaseOrder.aCustom9, " +
" aPurchaseOrder.aCustom0 " +
"FROM aPurchaseOrder " +
"LEFT OUTER JOIN aUser aModifierUser ON aPurchaseOrder.aModifier " +
"= aModifierUser.aID LEFT OUTER " +
"JOIN aUser aCreatorUser ON aPurchaseOrder.aCreator " +
"= aCreatorUser.aID LEFT OUTER JOIN aClient " +
"ON aPurchaseOrder.aDropShipToClientID = aClient.aID " +
"LEFT OUTER JOIN aVendor ON aPurchaseOrder.aVendorID " +
"= aVendor.aID " +
"LEFT OUTER JOIN aProject ON aPurchaseOrder.aProjectID " +
"= aProject.aID ";
//************************************************************
if (crit.MaxRecords > 0)
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
else
q = q.Replace("~MAXRECS~", "");
//List or grid criteria?
if (crit.IDList != null)
{
//Case 556
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
sbIN.Append(" WHERE (aPurchaseOrder.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(")) ");
cm = DBUtil.DB.GetSqlStringCommandWrapper(q + sbIN.ToString() + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
}
else
{
//Changed: 12-July-2006 the getgridcolumncriteria fragment was being called with addwhereclause parameter false instead of true
//Grid criteria
cm = DBUtil.DB.GetSqlStringCommandWrapper(q +
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,true) + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
}
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
while(dr.Read())
{
//*******************************************
PurchaseOrderListInfo info=new PurchaseOrderListInfo();
info.mPONumber=new GridNameValueCellItem(
dr.GetGuid("aID"),
dr.GetInt32("aPONumber").ToString(),
RootObjectTypes.PurchaseOrder);
info.mClient=new GridNameValueCellItem(
dr.GetGuid("aClientID"),
dr.GetString("aClientName"),
RootObjectTypes.Client);
info.mVendor=new GridNameValueCellItem(
dr.GetGuid("aVendorID"),
dr.GetString("aVendorName"),
RootObjectTypes.Vendor);
//case 49
info.mProject = new GridNameValueCellItem(
dr.GetGuid("aProjectID"),
dr.GetString("aProjectName"),
RootObjectTypes.Project);
info.mReferenceNumber=dr.GetString("aReferenceNumber");
info.mOrderedDate=DBUtil.ToLocal(dr.GetSmartDate("aOrderedDate"));
info.mExpectedReceiveDate=DBUtil.ToLocal(dr.GetSmartDate("aExpectedReceiveDate"));
info.mCreated=DBUtil.ToLocal(dr.GetDateTime("aCreatedDate"));
info.mModified=DBUtil.ToLocal(dr.GetDateTime("aModifiedDate"));
info.mCreatorInitials=dr.GetString("aCreatorInitials");
info.mModifierInitials=dr.GetString("aModifierInitials");
info.mStatus=(PurchaseOrderStatus)dr.GetInt16("aStatus");
//case 867
info.mCustom0 = dr.GetString("aCustom0");
info.mCustom1 = dr.GetString("aCustom1");
info.mCustom2 = dr.GetString("aCustom2");
info.mCustom3 = dr.GetString("aCustom3");
info.mCustom4 = dr.GetString("aCustom4");
info.mCustom5 = dr.GetString("aCustom5");
info.mCustom6 = dr.GetString("aCustom6");
info.mCustom7 = dr.GetString("aCustom7");
info.mCustom8 = dr.GetString("aCustom8");
info.mCustom9 = dr.GetString("aCustom9");
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 PurchaseOrderList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL