570 lines
19 KiB
C#
570 lines
19 KiB
C#
///////////////////////////////////////////////////////////
|
|
// AyaFileList.cs
|
|
// Implementation of Class AyaFileList
|
|
// CSLA type: Read only collection
|
|
// Created on: 31-Rocktober-2008
|
|
// Object design: John
|
|
// Coded: 31-Rocktober-2008
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Collections.Generic;
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Used to fetch a read only list of <see cref="AyaFileList.AyaFileListInfo"/> objects
|
|
/// representing <see cref="AyaFile"/> files stored inside the database.
|
|
///
|
|
/// Used for Wiki feature and for general file management by admin
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class AyaFileList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct AyaFileListInfo
|
|
{
|
|
|
|
internal GridNameValueCellItem mFile;
|
|
/// <summary>
|
|
/// File name an internal ID
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aName",
|
|
"aFile.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.AyaFile)]
|
|
public GridNameValueCellItem LT_O_AyaFile
|
|
{ get { return mFile; } }
|
|
|
|
internal GridNameValueCellItem mSource;
|
|
/// <summary>
|
|
/// Source of the file (which AyaNova object it's associated with)
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("grid"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.AyaFile)]
|
|
public GridNameValueCellItem LT_AyaFile_Label_Source
|
|
{
|
|
get
|
|
{
|
|
return mSource;
|
|
}
|
|
}
|
|
|
|
|
|
// Object to open to view this search results original record
|
|
// If this object is not a child or grandchild, then this is the same as RootObjectID
|
|
internal Guid mRootObjectID;
|
|
internal RootObjectTypes mRootObjectType;
|
|
/// <summary>
|
|
/// Files associated object ID
|
|
/// </summary>
|
|
[Display(DisplayType.Hidden)]
|
|
public Guid RootObjectID { get { return mRootObjectID; } }
|
|
|
|
/// <summary>
|
|
/// Files associated object type
|
|
/// </summary>
|
|
[Display(DisplayType.Hidden)]
|
|
public RootObjectTypes RootObjectType { get { return mRootObjectType; } }
|
|
|
|
/// <summary>
|
|
/// The <see cref="AyaFileType"/> of this file
|
|
/// </summary>
|
|
// [SqlColumnNameAttribute("aFile.aFileType"), Display(DisplayType.Text)]
|
|
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
|
|
public AyaFileType FileType { get { return mFileType; } }
|
|
internal AyaFileType mFileType;
|
|
|
|
internal string mFileSize;
|
|
/// <summary>
|
|
/// File size converted to largest whole display unit and unit type appended (i.e. 10MB) see
|
|
/// <see cref="AyaBizUtils.FileSizeDisplay"/> for more.
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aFileSize"), Display(DisplayType.Text)]
|
|
public string LT_AyaFile_Label_FileSize { get { return mFileSize; } }
|
|
|
|
internal int mFileSizeBytes;
|
|
/// <summary>
|
|
/// File size in bytes (actual file size when uncompressed, stored in DB compressed where possible)
|
|
/// </summary>
|
|
[Display(DisplayType.Hidden)]
|
|
public int FileSizeBytes { get { return mFileSizeBytes; } }
|
|
|
|
internal string mFileSizeStored;
|
|
/// <summary>
|
|
/// Actual size as stored in Database in human readable format (<see cref="AyaBizUtils.FileSizeDisplay"/>)
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aFObjectSize"), Display(DisplayType.Text)]
|
|
public string LT_AyaFile_Label_FileSizeStored { get { return mFileSizeStored; } }
|
|
|
|
internal SmartDate mCreated;
|
|
/// <summary>
|
|
/// DateTime the record was created
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aCreated"), Display(DisplayType.DateTime)]
|
|
public object LT_Common_Label_Created { get { return mCreated.DBValue; } }
|
|
|
|
internal SmartDate mModified;
|
|
/// <summary>
|
|
/// Date and time this record was last modified
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aModified"), Display(DisplayType.DateTime)]
|
|
public object LT_Common_Label_Modified { get { return mModified.DBValue; } }
|
|
|
|
internal GridNameValueCellItem mCreator;
|
|
/// <summary>
|
|
/// Creator of record
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aCreator",
|
|
"aFile.aCreator"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_Common_Label_Creator { get { return mCreator; } }
|
|
|
|
internal GridNameValueCellItem mModifier;
|
|
/// <summary>
|
|
/// User who last modified this record
|
|
/// </summary>
|
|
[SqlColumnNameAttribute("aFile.aModifier",
|
|
"aFile.aModifier"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_Common_Label_Modifier { get { return mModifier; } }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(AyaFileListInfo obj)
|
|
{
|
|
return this.mFile.Value.Equals(obj.mFile.Value);
|
|
}
|
|
|
|
}//end AyaFileListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected AyaFileList()
|
|
{
|
|
// 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 AyaFileListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (AyaFileListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns AyaFileListInfo object that matches passed in File Name value
|
|
/// </summary>
|
|
/// <param name="FileName"></param>
|
|
public AyaFileListInfo? this[string FileName]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (AyaFileListInfo child in List)
|
|
{
|
|
if (child.LT_O_AyaFile.Display == FileName) return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (AyaFileListInfo child in List)
|
|
{
|
|
if(child.mFile.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(AyaFileListInfo obj)
|
|
{
|
|
foreach (AyaFileListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by file name
|
|
/// </summary>
|
|
/// <param name="FileName"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(string FileName)
|
|
{
|
|
foreach (AyaFileListInfo child in List)
|
|
{
|
|
if (child.LT_O_AyaFile.Display==FileName) 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 "AyaFileList";
|
|
}
|
|
}
|
|
|
|
/// <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.AyaFile;
|
|
}
|
|
}
|
|
|
|
/// <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 "AyaFile.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(AyaFileListInfo);
|
|
}
|
|
}
|
|
/// <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_AyaFile";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Get all for given RootObjectID
|
|
/// (typically the ID of a WikiPage
|
|
/// </summary>
|
|
/// <param name="RootObjectID"></param>
|
|
/// <returns>List of <see cref="AyaFileList.AyaFileListInfo"/> objects</returns>
|
|
public static AyaFileList GetList(Guid RootObjectID)
|
|
{
|
|
return (AyaFileList) DataPortal.Fetch(new Criteria("",null,-1,RootObjectID));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static AyaFileList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (AyaFileList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords, Guid.Empty));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all (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="AyaFileList.AyaFileListInfo"/> objects</returns>
|
|
public static AyaFileList GetList(string xmlCriteria)
|
|
{
|
|
return (AyaFileList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1, Guid.Empty));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>List of <see cref="AyaFileList.AyaFileListInfo"/> objects</returns>
|
|
public static AyaFileList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new AyaFileList();
|
|
return (AyaFileList)DataPortal.Fetch(new Criteria("", IDList, -1, Guid.Empty));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Used internally to fetch info for a single specific file
|
|
/// </summary>
|
|
/// <param name="AyaFileID"></param>
|
|
/// <returns>List of <see cref="AyaFileList.AyaFileListInfo"/> one object</returns>
|
|
public static AyaFileList GetListOfOne(Guid AyaFileID)
|
|
{
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(AyaFileID);
|
|
return GetListFromIDList(l);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns>Empty List of zero <see cref="AyaFileList.AyaFileListInfo"/> objects</returns>
|
|
public static AyaFileList GetEmptyList()
|
|
{
|
|
return new AyaFileList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
//cached user list
|
|
UserPickList users = UserPickList.GetList(false);
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
string q = "";
|
|
//************************************************************
|
|
if (crit.RootObjectID != Guid.Empty)
|
|
{ //Standard case for wikipages
|
|
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT aID, aCreated,aModified,aCreator,aModifier, " +
|
|
"aRootObjectID, aRootObjectType, aFileType, aName, aFileSize, aFObjectSize " +
|
|
"FROM aFile WHERE aRootObjectID=@ID ", crit.RootObjectID);
|
|
}
|
|
else if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" WHERE aFile.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 aID, aCreated,aModified,aCreator,aModifier, " +
|
|
"aRootObjectID, aRootObjectType, aFileType, aName, aFileSize, aFObjectSize " +
|
|
"FROM aFile " +
|
|
sbIN.ToString() + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q);
|
|
}
|
|
else
|
|
{
|
|
q = "SELECT ~MAXRECS~ aID, aCreated,aModified,aCreator,aModifier, " +
|
|
"aRootObjectID, aRootObjectType, aFileType, aName, aFileSize, aFObjectSize " +
|
|
"FROM aFile " + //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~", "");
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q);
|
|
}
|
|
//************************************************************
|
|
|
|
|
|
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
AyaFileListInfo info=new AyaFileListInfo();
|
|
|
|
info.mFileType = (AyaFileType)dr.GetInt16("aFileType");
|
|
|
|
////Don't load image files into list when in a wikipage
|
|
////as they are handled internally, no need to show to user and confuse them
|
|
//if (crit.RootObjectID != Guid.Empty)//it's a wikipage
|
|
// if (info.mFileType == AyaFileType.EmbeddedWikiImage)
|
|
// continue;
|
|
|
|
info.mFile=new GridNameValueCellItem(
|
|
dr.GetGuid("aID"),
|
|
dr.GetString("aName"),
|
|
RootObjectTypes.AyaFile);
|
|
|
|
info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
|
|
info.mCreator = new GridNameValueCellItem(
|
|
dr.GetGuid("aCreator"),
|
|
users[dr.GetGuid("aCreator")],
|
|
RootObjectTypes.User);
|
|
|
|
info.mModifier = new GridNameValueCellItem(
|
|
dr.GetGuid("aModifier"),
|
|
users[dr.GetGuid("aModifier")],
|
|
RootObjectTypes.User);
|
|
|
|
info.mModified = DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
|
|
info.mFileSize = AyaBizUtils.FileSizeDisplay(System.Convert.ToDecimal(dr.GetInt32("aFileSize")));
|
|
info.mFileSizeStored = AyaBizUtils.FileSizeDisplay(System.Convert.ToDecimal(dr.GetInt32("aFObjectSize")));
|
|
info.mFileSizeBytes = dr.GetInt32("aFileSize");
|
|
|
|
|
|
info.mRootObjectID = dr.GetGuid("aRootObjectID");
|
|
info.mRootObjectType = (RootObjectTypes)dr.GetInt16("aRootObjectType");
|
|
|
|
|
|
|
|
info.mSource = new GridNameValueCellItem(
|
|
info.mRootObjectID,
|
|
EnumDescConverter.GetEnumDescription(info.mRootObjectType),
|
|
info.mRootObjectType);
|
|
|
|
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 Guid RootObjectID;
|
|
public Criteria(string _CriteriaXML, List<Guid> _IDList, int _MaxRecords,Guid _RootObjectID)
|
|
{
|
|
CriteriaXML = _CriteriaXML;
|
|
IDList = _IDList;
|
|
MaxRecords = _MaxRecords;
|
|
RootObjectID=_RootObjectID;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end AyaFileList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL
|