CSLA - Is
This commit is contained in:
@@ -13,8 +13,6 @@ using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Csla;
|
||||
using Csla.Data;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
namespace VEPROMS.CSLA.Library
|
||||
@@ -30,8 +28,7 @@ namespace VEPROMS.CSLA.Library
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#endregion
|
||||
#region Business Methods
|
||||
internal new IList<ItemInfo> Items
|
||||
{ get { return base.Items; } }
|
||||
internal new IList<ItemInfo> Items => base.Items;
|
||||
public void AddEvents()
|
||||
{
|
||||
foreach (ItemInfo tmp in this)
|
||||
@@ -48,14 +45,13 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
void tmp_Deleted(object sender)
|
||||
{
|
||||
ItemInfo ii = sender as ItemInfo;
|
||||
if (ii != null)
|
||||
if (sender is ItemInfo ii)
|
||||
{
|
||||
RefreshingList = true;
|
||||
IsReadOnly = false;
|
||||
Remove(ii);
|
||||
IsReadOnly = true;
|
||||
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0));
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0));
|
||||
RefreshingList = false;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +71,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (SourceOfList != "Search" && (sender as ItemInfo).MyPrevious != null && i > 0 && base[i - 1].ItemID != (sender as ItemInfo).MyPrevious.ItemID)
|
||||
Items.Insert(i, (sender as ItemInfo).MyPrevious);
|
||||
IsReadOnly = true;
|
||||
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
|
||||
RefreshingList = false;
|
||||
break;
|
||||
}
|
||||
@@ -87,27 +83,15 @@ namespace VEPROMS.CSLA.Library
|
||||
get { return _SourceOfList; }
|
||||
set { _SourceOfList = value; }
|
||||
}
|
||||
//private void ShowList(string txt)
|
||||
//{
|
||||
// Console.WriteLine("\r\n{0} - {1} - {2}: i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText", txt, Count, SourceOfList);
|
||||
// for (int i = 0; i < Count; i++)
|
||||
// {
|
||||
// Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText, base[i].MyItemInfoUnique, base[i].Disposed);
|
||||
// }
|
||||
//}
|
||||
private bool _Disposed = false;
|
||||
private static int _CountCreated = 0;
|
||||
private static int _CountDisposed = 0;
|
||||
private static int _CountFinalized = 0;
|
||||
private static int IncrementCountCreated
|
||||
{ get { return ++_CountCreated; } }
|
||||
private int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated
|
||||
{ get { return _CountCreated; } }
|
||||
public static int CountNotDisposed
|
||||
{ get { return _CountCreated - _CountDisposed; } }
|
||||
public static int CountNotFinalized
|
||||
{ get { return _CountCreated - _CountFinalized; } }
|
||||
private static int IncrementCountCreated => ++_CountCreated;
|
||||
private readonly int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated => _CountCreated;
|
||||
public static int CountNotDisposed => _CountCreated - _CountDisposed;
|
||||
public static int CountNotFinalized => _CountCreated - _CountFinalized;
|
||||
~ItemInfoList()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -149,22 +133,7 @@ namespace VEPROMS.CSLA.Library
|
||||
/// <summary>
|
||||
/// Reset the list of all ItemInfo.
|
||||
/// </summary>
|
||||
public static void Reset()
|
||||
{
|
||||
_ItemInfoList = null;
|
||||
}
|
||||
// CSLATODO: Add alternative gets -
|
||||
//public static ItemInfoList Get(<criteria>)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// return DataPortal.Fetch<ItemInfoList>(new FilteredCriteria(<criteria>));
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// throw new DbCslaException("Error on ItemInfoList.Get", ex);
|
||||
// }
|
||||
//}
|
||||
public static void Reset() => _ItemInfoList = null;
|
||||
public static ItemInfoList GetNext(int? previousID)
|
||||
{
|
||||
try
|
||||
@@ -199,7 +168,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
private void DataPortal_Fetch()
|
||||
{
|
||||
this.RaiseListChangedEvents = false;
|
||||
RaiseListChangedEvents = false;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_Fetch", GetHashCode());
|
||||
try
|
||||
{
|
||||
@@ -213,7 +182,7 @@ namespace VEPROMS.CSLA.Library
|
||||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||||
{
|
||||
IsReadOnly = false;
|
||||
while (dr.Read()) this.Add(new ItemInfo(dr));
|
||||
while (dr.Read()) Add(new ItemInfo(dr));
|
||||
IsReadOnly = true;
|
||||
}
|
||||
}
|
||||
@@ -224,15 +193,12 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_Fetch", ex);
|
||||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||||
}
|
||||
this.RaiseListChangedEvents = true;
|
||||
RaiseListChangedEvents = true;
|
||||
}
|
||||
[Serializable()]
|
||||
private class PreviousIDCriteria
|
||||
{
|
||||
public PreviousIDCriteria(int? previousID)
|
||||
{
|
||||
_PreviousID = previousID;
|
||||
}
|
||||
public PreviousIDCriteria(int? previousID) => _PreviousID = previousID;
|
||||
private int? _PreviousID;
|
||||
public int? PreviousID
|
||||
{
|
||||
@@ -242,7 +208,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private void DataPortal_Fetch(PreviousIDCriteria criteria)
|
||||
{
|
||||
this.RaiseListChangedEvents = false;
|
||||
RaiseListChangedEvents = false;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchPreviousID", GetHashCode());
|
||||
try
|
||||
{
|
||||
@@ -257,7 +223,7 @@ namespace VEPROMS.CSLA.Library
|
||||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||||
{
|
||||
IsReadOnly = false;
|
||||
while (dr.Read()) this.Add(new ItemInfo(dr));
|
||||
while (dr.Read()) Add(new ItemInfo(dr));
|
||||
IsReadOnly = true;
|
||||
}
|
||||
}
|
||||
@@ -268,15 +234,12 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchPreviousID", ex);
|
||||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||||
}
|
||||
this.RaiseListChangedEvents = true;
|
||||
RaiseListChangedEvents = true;
|
||||
}
|
||||
[Serializable()]
|
||||
private class ContentIDCriteria
|
||||
{
|
||||
public ContentIDCriteria(int contentID)
|
||||
{
|
||||
_ContentID = contentID;
|
||||
}
|
||||
public ContentIDCriteria(int contentID) => _ContentID = contentID;
|
||||
private int _ContentID;
|
||||
public int ContentID
|
||||
{
|
||||
@@ -286,7 +249,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private void DataPortal_Fetch(ContentIDCriteria criteria)
|
||||
{
|
||||
this.RaiseListChangedEvents = false;
|
||||
RaiseListChangedEvents = false;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchContentID", GetHashCode());
|
||||
try
|
||||
{
|
||||
@@ -301,7 +264,7 @@ namespace VEPROMS.CSLA.Library
|
||||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||||
{
|
||||
IsReadOnly = false;
|
||||
while (dr.Read()) this.Add(new ItemInfo(dr));
|
||||
while (dr.Read()) Add(new ItemInfo(dr));
|
||||
IsReadOnly = true;
|
||||
}
|
||||
}
|
||||
@@ -312,38 +275,27 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchContentID", ex);
|
||||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||||
}
|
||||
this.RaiseListChangedEvents = true;
|
||||
RaiseListChangedEvents = true;
|
||||
}
|
||||
#endregion
|
||||
#region ICustomTypeDescriptor impl
|
||||
public String GetClassName()
|
||||
{ return TypeDescriptor.GetClassName(this, true); }
|
||||
public AttributeCollection GetAttributes()
|
||||
{ return TypeDescriptor.GetAttributes(this, true); }
|
||||
public String GetComponentName()
|
||||
{ return TypeDescriptor.GetComponentName(this, true); }
|
||||
public TypeConverter GetConverter()
|
||||
{ return TypeDescriptor.GetConverter(this, true); }
|
||||
public EventDescriptor GetDefaultEvent()
|
||||
{ return TypeDescriptor.GetDefaultEvent(this, true); }
|
||||
public PropertyDescriptor GetDefaultProperty()
|
||||
{ return TypeDescriptor.GetDefaultProperty(this, true); }
|
||||
public object GetEditor(Type editorBaseType)
|
||||
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
|
||||
public EventDescriptorCollection GetEvents(Attribute[] attributes)
|
||||
{ return TypeDescriptor.GetEvents(this, attributes, true); }
|
||||
public EventDescriptorCollection GetEvents()
|
||||
{ return TypeDescriptor.GetEvents(this, true); }
|
||||
public object GetPropertyOwner(PropertyDescriptor pd)
|
||||
{ return this; }
|
||||
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
|
||||
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
|
||||
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
|
||||
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
|
||||
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
|
||||
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
|
||||
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
|
||||
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
|
||||
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
|
||||
public object GetPropertyOwner(PropertyDescriptor pd) => this;
|
||||
/// <summary>
|
||||
/// Called to get the properties of this type. Returns properties with certain
|
||||
/// attributes. this restriction is not implemented here.
|
||||
/// </summary>
|
||||
/// <param name="attributes"></param>
|
||||
/// <returns></returns>
|
||||
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
|
||||
{ return GetProperties(); }
|
||||
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
|
||||
/// <summary>
|
||||
/// Called to get the properties of this type.
|
||||
/// </summary>
|
||||
@@ -353,7 +305,7 @@ namespace VEPROMS.CSLA.Library
|
||||
// Create a collection object to hold property descriptors
|
||||
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
|
||||
// Iterate the list
|
||||
for (int i = 0; i < this.Items.Count; i++)
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
// Create a property descriptor for the item and add to the property descriptor collection
|
||||
ItemInfoListPropertyDescriptor pd = new ItemInfoListPropertyDescriptor(this, i);
|
||||
@@ -370,7 +322,6 @@ namespace VEPROMS.CSLA.Library
|
||||
/// </summary>
|
||||
public partial class ItemInfoListPropertyDescriptor : vlnListPropertyDescriptor
|
||||
{
|
||||
private ItemInfo Item { get { return (ItemInfo)_Item; } }
|
||||
public ItemInfoListPropertyDescriptor(ItemInfoList collection, int index) : base(collection, index) {; }
|
||||
}
|
||||
#endregion
|
||||
@@ -379,10 +330,10 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
||||
{
|
||||
if (destType == typeof(string) && value is ItemInfoList)
|
||||
if (destType == typeof(string) && value is ItemInfoList list)
|
||||
{
|
||||
// Return department and department role separated by comma.
|
||||
return ((ItemInfoList)value).Items.Count.ToString() + " Items";
|
||||
return $"{list.Items.Count} Items";
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user