481 lines
15 KiB
C#
481 lines
15 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ProjectList.cs
|
|
// Implementation of Class ProjectList
|
|
// CSLA type: Read only collection
|
|
// Created on: 09-Sept-2005
|
|
// Object design: John
|
|
// Coded: 09-Sept-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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>
|
|
/// Lightweight read only list of <see cref="ProjectList.ProjectListInfo"/> objects representing <see cref="Project"/> objects. For user selection and internal use by API business objects.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ProjectList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct ProjectListInfo
|
|
{
|
|
internal GridNameValueCellItem mName; //and ID
|
|
internal GridNameValueCellItem mProjectOverseer; //and ID
|
|
internal SmartDate mDateStarted;
|
|
internal SmartDate mDateCompleted;
|
|
internal bool mActive;
|
|
internal string mAccountNumber;
|
|
|
|
|
|
|
|
|
|
[SqlColumnNameAttribute("aProject.aName",
|
|
"aProject.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Project)]
|
|
public GridNameValueCellItem LT_O_Project
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aUser.aInitials",
|
|
"aProject.aProjectOverseerID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_Project_Label_ProjectOverseerID
|
|
{
|
|
get
|
|
{
|
|
return mProjectOverseer;
|
|
}
|
|
}
|
|
|
|
|
|
[Display(DisplayType.DateTime)]
|
|
public object LT_Project_Label_DateStarted
|
|
{
|
|
get
|
|
{
|
|
return this.mDateStarted.DBValue;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.DateTime)]
|
|
public object LT_Project_Label_DateCompleted
|
|
{
|
|
get
|
|
{
|
|
return this.mDateCompleted.DBValue;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aProject.AACCOUNTNUMBER"), Display(DisplayType.Text)]
|
|
public string LT_Project_Label_AccountNumber
|
|
{
|
|
get
|
|
{
|
|
return this.mAccountNumber;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_Project_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//Case 58
|
|
internal GridNameValueCellItem mRegion;
|
|
[SqlColumnNameAttribute("aRegion.aName", "aRegion.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region)]
|
|
public GridNameValueCellItem LT_O_Region
|
|
{
|
|
get
|
|
{
|
|
return mRegion;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(ProjectListInfo obj)
|
|
{
|
|
return this.mName.Value.Equals(obj.mName.Value);
|
|
}
|
|
|
|
}//end ProjectListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected ProjectList()
|
|
{
|
|
// 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 ProjectListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ProjectListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (ProjectListInfo child in List)
|
|
{
|
|
if(child.mName.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(ProjectListInfo obj)
|
|
{
|
|
foreach (ProjectListInfo 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 "ProjectList";
|
|
}
|
|
}
|
|
|
|
/// <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 "";
|
|
}
|
|
}
|
|
|
|
/// <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.Project;
|
|
}
|
|
}
|
|
|
|
/// <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 "Project.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(ProjectListInfo);
|
|
}
|
|
}
|
|
/// <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_O_Project";
|
|
}
|
|
}
|
|
/// <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 ProjectList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (ProjectList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all Project (filtered by crit)
|
|
/// </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="ProjectList.ProjectListInfo"/> objects</returns>
|
|
public static ProjectList GetList(string xmlCriteria)
|
|
{
|
|
return (ProjectList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>list of <see cref="ProjectList.ProjectListInfo"/> objects</returns>
|
|
public static ProjectList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new ProjectList();
|
|
return (ProjectList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ProjectList GetEmptyList()
|
|
{
|
|
return new ProjectList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
string q = "";
|
|
//************************************************************
|
|
if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" WHERE aProject.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(") ");
|
|
|
|
|
|
|
|
q = "SELECT aProject.aID AS aProjectID, aProject.aName AS aProjectName, aUser.aFirstName, " +
|
|
" aUser.aLastName, aUser.aInitials, AUSERREGIONTABLE.ANAME AS AUSERREGIONNAME, " +
|
|
" aUser.aEmployeeNumber, aProject.aDateCompleted, " +
|
|
" aProject.aRegionID, aRegion.aName AS aRegionName, " + //case 58
|
|
" aProject.AACCOUNTNUMBER, aProject.aDateStarted, " +
|
|
" aProject.AACTIVE, aProject.aProjectOverseerID " +
|
|
"FROM aProject LEFT OUTER " +
|
|
"JOIN aUser ON aProject.aProjectOverseerID " +
|
|
"= aUser.aID " +
|
|
" LEFT OUTER JOIN AREGION AUSERREGIONTABLE ON (AUSER.AREGIONID=AUSERREGIONTABLE.AID) " +
|
|
"LEFT OUTER JOIN aRegion ON aProject.aRegionID = aRegion.aID " + //Case 58
|
|
|
|
sbIN.ToString() + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
}
|
|
else
|
|
{
|
|
q = "SELECT ~MAXRECS~ aProject.aID AS aProjectID, aProject.aName AS aProjectName, aUser.aFirstName, " +
|
|
" aUser.aLastName, aUser.aInitials, AUSERREGIONTABLE.ANAME AS AUSERREGIONNAME, " +
|
|
" aUser.aEmployeeNumber, aProject.aDateCompleted, " +
|
|
" aProject.aRegionID, aRegion.aName AS aRegionName, " + //case 58
|
|
" aProject.AACCOUNTNUMBER, aProject.aDateStarted, " +
|
|
" aProject.AACTIVE, aProject.aProjectOverseerID " +
|
|
"FROM aProject LEFT OUTER " +
|
|
"JOIN aUser ON aProject.aProjectOverseerID " +
|
|
"= aUser.aID " +
|
|
" LEFT OUTER JOIN AREGION AUSERREGIONTABLE ON (AUSER.AREGIONID=AUSERREGIONTABLE.AID) " +
|
|
"LEFT OUTER JOIN aRegion ON aProject.aRegionID = aRegion.aID " + //Case 58;
|
|
|
|
|
|
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, true) + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
q = DBUtil.AddRegionFilter(q, "aProject", "");//case 58
|
|
}
|
|
//************************************************************
|
|
|
|
|
|
dr=DBUtil.GetReaderFromSQLString(q);
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
ProjectListInfo info=new ProjectListInfo();
|
|
|
|
|
|
info.mName=new GridNameValueCellItem(
|
|
dr.GetGuid("aProjectID"),
|
|
dr.GetString("aProjectName"),
|
|
RootObjectTypes.Project);
|
|
|
|
info.mProjectOverseer=new GridNameValueCellItem(
|
|
dr.GetGuid("aProjectOverseerID"),
|
|
User.NameFormatter(dr.GetString("aFirstName"),dr.GetString("aLastName"),dr.GetString("aInitials"),
|
|
dr.GetString("aEmployeeNumber"), dr.GetString("AUSERREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat),
|
|
RootObjectTypes.User);
|
|
|
|
//Case 58
|
|
info.mRegion = new GridNameValueCellItem(
|
|
dr.GetGuid("aRegionID"),
|
|
dr.GetString("aRegionName"),
|
|
RootObjectTypes.Region);
|
|
|
|
info.mAccountNumber=dr.GetString("AACCOUNTNUMBER");
|
|
|
|
info.mDateStarted=DBUtil.ToLocal(dr.GetSmartDate("aDateStarted"));
|
|
info.mDateCompleted=DBUtil.ToLocal(dr.GetSmartDate("aDateCompleted"));
|
|
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
|
|
{
|
|
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 ProjectList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |