Added DocStyleListConverter and Sorted Format List Lazy-load

This commit is contained in:
Rich 2008-08-13 12:36:18 +00:00
parent baf43ff8a2
commit 6a7fa65e43

View File

@ -41,23 +41,32 @@ namespace VEPROMS.CSLA.Library
}
public class FormatList : System.ComponentModel.StringConverter
{
private static SortedList<string,FormatInfo> _FormatInfoList;
private static SortedList<string, FormatInfo> _MyFormatInfoList;
public static SortedList<string, FormatInfo> MyFormatInfoList
{
get
{
if (_MyFormatInfoList == null)
LoadSortedList();
return FormatList._MyFormatInfoList;
}
}
private static void LoadSortedList()
{
if (_FormatInfoList == null)
if (_MyFormatInfoList == null)
{
_FormatInfoList = new SortedList<string, FormatInfo>();
_MyFormatInfoList = new SortedList<string, FormatInfo>();
foreach (FormatInfo formatInfo in FormatInfoList.Get())
{
_FormatInfoList.Add(formatInfo.Name, formatInfo);
//_FormatInfoList.Add(formatInfo.Name, formatInfo);
_MyFormatInfoList.Add(formatInfo.FullName, formatInfo);
}
_FormatInfoList.Add("", null);
_MyFormatInfoList.Add("", null);
}
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
LoadSortedList();
return new StandardValuesCollection((ICollection)_FormatInfoList.Values);
return new StandardValuesCollection((ICollection)MyFormatInfoList.Values);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
@ -70,26 +79,84 @@ namespace VEPROMS.CSLA.Library
public static int? ToInt(string formatName)
{
if (formatName == null || formatName == string.Empty) return null;
LoadSortedList();
foreach (FormatInfo formatInfo in _FormatInfoList.Values)
if (formatInfo != null && formatInfo.Name == formatName) return formatInfo.FormatID;
foreach (FormatInfo formatInfo in MyFormatInfoList.Values)
if (formatInfo != null && formatInfo.FullName == formatName) return formatInfo.FormatID;
return null;
}
public static string ToString(int? formatID)
{
if (formatID == null) return null;
LoadSortedList();
foreach (FormatInfo formatInfo in _FormatInfoList.Values)
foreach (FormatInfo formatInfo in MyFormatInfoList.Values)
if (formatInfo != null && formatInfo.FormatID == formatID) return formatInfo.ToString();
return null;
}
public static Format ToFormat(string formatName)
{
if (formatName == null || formatName == string.Empty) return null;
LoadSortedList();
foreach (FormatInfo formatInfo in _FormatInfoList.Values)
foreach (FormatInfo formatInfo in MyFormatInfoList.Values)
if (formatInfo != null && formatInfo.ToString() == formatName) return formatInfo.Get();
return null;
}
}
public class DocStyleListConverter : System.ComponentModel.StringConverter
{
private static SortedList<string, int> _MyDocStyleList;
private static SortedList<string, int> MyDocStyleList
{
get
{
if (_MyDocStyleList == null)
LoadSortedList();
return _MyDocStyleList;
}
set { _MyDocStyleList = value; }
}
private static Section _MySection;
public static Section MySection
{
get { return _MySection; }
set
{
_MySection = value;
_MyDocStyleList = null;
}
}
private static void LoadSortedList()
{
if (_MyDocStyleList == null)
{
_MyDocStyleList = new SortedList<string, int>();
foreach(DocStyle ds in _MySection.ActiveFormat.PlantFormat.DocStyles.DocStyleList)
{
_MyDocStyleList.Add(ds.Name,10000 + (int) ds.Index);
}
}
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection((ICollection)MyDocStyleList.Keys);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
public static int? ToInt(string docStyleName)
{
return MyDocStyleList[docStyleName];
}
public static string ToString(int? sectionType)
{
if (sectionType == null) return null;
return MyDocStyleList.Keys[MyDocStyleList.IndexOfValue((int)sectionType)];
}
public static int ToSectionType(string docStyleName)
{
return MyDocStyleList[docStyleName];
}
}
}