2009-02-04 13:14:57 +00:00

527 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using DescriptiveEnum;
namespace VEPROMS.CSLA.Library
{
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class SectionConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged
{
#region DynamicTypeDescriptor
internal override bool IsReadOnly
{
get { return false; }//_Section == null; }
}
#endregion
#region XML
private XMLProperties _Xp;
private XMLProperties Xp
{
get { return _Xp; }
}
#endregion
#region Constructors
//PROPGRID: Hide ParentLookup
[Browsable(false)]
public bool ParentLookup
{
get { return _Xp.ParentLookup; }
set { _Xp.ParentLookup = value; }
}
//PROPGRID: Had to comment out NonSerialized to hide AncestorLookup from Property Grid
//[NonSerialized]
private bool _AncestorLookup;
//PROPGRID: Hide AncestorLookup
[Browsable(false)]
public bool AncestorLookup
{
get { return _AncestorLookup; }
set { _AncestorLookup = value; }
}
private Section _Section;
private SectionInfo _SectionInfo;
public SectionConfig(Section section)
{
_Section = section;
string xml = section.MyContent.Config;
if (xml == string.Empty) xml = "<config/>";
_Xp = new XMLProperties(xml);
if (section.ActiveParent != null) _Xp.LookInAncestor += new XMLPropertiesEvent(Xp_LookInAncestorFolder);
}
private string Xp_LookInAncestorFolder(object sender, XMLPropertiesArgs args)
{
if (_AncestorLookup || ParentLookup)
{
string retval;
Section sect = _Section;
while (sect.ActiveParent.GetType() == typeof(Section))
{
retval = sect.SectionConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
sect = (Section)sect.ActiveParent;
}
Procedure proc = (Procedure)sect.ActiveParent;
while (proc.ActiveParent.GetType() == typeof(Procedure))
{
retval = proc.ProcedureConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
proc = (Procedure)proc.ActiveParent;
}
DocVersion docVersion = (DocVersion)proc.ActiveParent;
retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
for (Folder folder = docVersion.MyFolder; folder != null; folder = folder.MyParent)
{
retval = folder.FolderConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
}
}
return string.Empty;
}
private string Xp_LookInAncestorFolderInfo(object sender, XMLPropertiesArgs args)
{
if (_AncestorLookup || ParentLookup)
{
string retval;
Section sect = _Section;
while (sect.ActiveParent.GetType() == typeof(Section))
{
//retval = sect.SectionConfig.GetValue(args.Group, args.Item);
//if (retval != string.Empty) return retval;
sect = (Section)sect.ActiveParent;
}
Procedure proc = (Procedure)sect.ActiveParent;
DocVersionInfo docVersion = (DocVersionInfo)proc.ActiveParent;
retval = docVersion.DocVersionConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
for (FolderInfo folder = docVersion.MyFolder; folder != null; folder = folder.MyParent)
{
retval = folder.FolderConfig.GetValue(args.Group, args.Item);
if (retval != string.Empty) return retval;
}
}
return string.Empty;
}
public SectionConfig(SectionInfo sectionInfo)
{
_SectionInfo = sectionInfo;
string xml = sectionInfo.MyContent.Config;
if (xml == string.Empty) xml = "<config/>";
_Xp = new XMLProperties(xml);
}
public SectionConfig(string xml)
{
if (xml == string.Empty) xml = "<config/>";
_Xp = new XMLProperties(xml);
}
public SectionConfig()
{
_Xp = new XMLProperties();
}
internal string GetValue(string group, string item)
{
return _Xp[group, item];
}
#endregion
#region Local Properties
//[Category("Identification")]
[Category("General")]
[DisplayName("Number")]
[Description("Number")]
public string Number
{
get { return (_Section != null ? _Section.MyContent.Number : _SectionInfo.MyContent.Number); }
set { if (_Section != null) _Section.MyContent.Number = value; }
}
//[Category("Identification")]
[Category("General")]
[DisplayName("Title")]
[Description("Title")]
public string Title
{
get { return (_Section != null ? _Section.MyContent.Text : _SectionInfo.MyContent.Text); }
set { if (_Section != null) _Section.MyContent.Text = value; }
}
[Category("Identification")]
//PROPGRID: Hide Old Sequence
[Browsable(false)]
[DisplayName("Old Sequence")]
[Description("Old Sequence")]
public string OldSequence
{
get { return (_Section != null ? _Section.MyContent.MyZContent.OldStepSequence : (_SectionInfo.MyContent.MyZContent == null ? null : _SectionInfo.MyContent.MyZContent.OldStepSequence)); }
set { if (_Section != null) _Section.MyContent.MyZContent.OldStepSequence = value; }
}
[Category("Identification")]
//PROPGRID: Hide Dirty
[Browsable(false)]
[DisplayName("Dirty")]
[Description("Dirty")]
public bool Dirty
{
get { return (_Section != null ? _Section.IsDirty : false); }
}
[Category("Format")]
[DisplayName("Format")]
[Description("Format")]
[TypeConverter(typeof(FormatList))]
public string FormatSelection
{
get
{
if (_Section != null && _Section.MyContent.MyFormat != null) return _Section.MyContent.MyFormat.FullName;
if (_SectionInfo != null && _SectionInfo.MyContent.MyFormat != null) return _SectionInfo.MyContent.MyFormat.FullName;
return null;
}
set
{
if (_Section != null)
{
_Section.MyContent.MyFormat = FormatList.ToFormat(value); // Can only be set if _DocVersion is set
_Section.ActiveFormat = null;
DocStyleListConverter.MySection = _Section;
}
}
}
[Browsable(false)]
public FormatInfo MyFormat
{
get
{
if (_Section != null)
{
SectionInfo sectionInfo = SectionInfo.Get(_Section.ItemID);
return sectionInfo.LocalFormat;
}
return _SectionInfo.LocalFormat;
}
set
{
if (_Section != null)
_Section.MyContent.MyFormat = value == null ? null : value.Get();
}
}
[Category("Format")]
[DisplayName("Default Format")]
[Description("Default Format")]
[TypeConverter(typeof(FormatList))]
public string DefaultFormatSelection
{
get
{
if (_Section != null && _Section.ActiveParent != null && _Section.ActiveParent.ActiveFormat != null) return _Section.ActiveParent.ActiveFormat.FullName;
if (_SectionInfo != null && _SectionInfo.MyParent != null && _SectionInfo.MyParent.ActiveFormat != null) return _SectionInfo.MyParent.ActiveFormat.FullName;
return null;
}
}
[Browsable(false)]
public FormatInfo MyDefaultFormat
{
get
{
if (_Section != null)
{
SectionInfo sectionInfo = SectionInfo.Get(_Section.ItemID);
return sectionInfo.ActiveParent.ActiveFormat;
}
return _SectionInfo.ActiveParent.ActiveFormat;
}
}
//[Browsable(false)]
[Category("Format")]
[DisplayName("Section Type")]
[Description("Section Type")]
[TypeConverter(typeof(DocStyleListConverter))]
public string MySectionType
{
get
{
if (_Section != null)
{
return DocStyleListConverter.ToString(_Section.MyContent.Type);
}
return string.Empty;
}
set
{
if (_Section != null)
_Section.MyContent.Type = DocStyleListConverter.ToSectionType(value);
}
}
[Browsable(false)]
public int? SectionType
{
get
{
if (_Section != null)
{
return _Section.MyContent.Type-10000;
}
return null;
}
set
{
if (_Section != null)
_Section.MyContent.Type = value+10000;
}
}
public Section MySection
{ get { return _Section; } }
#endregion
#region ToString
public override string ToString()
{
string s = _Xp.ToString();
if (s == "<config/>" || s == "<config></config>") return string.Empty;
return s;
}
#endregion
#region SectionCategory // from sequence number in 16-bit database.
public enum SectionPagination : int
{
Default = 0, Continuous, Separate
}
[Category("Format")]
[DisplayName("Section Pagination")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section Pagination")]
public SectionPagination Section_Pagination
{
get
{
string s = _Xp["Section", "Pagination"];
//If there is no value to get, then get the parent value (a.k.a. default value).
if (s == string.Empty)
s = _Xp.ParentValue("Section", "Pagination"); // get the parent value
// If there is no parent value, then use the volian default
if (s == string.Empty)
return SectionPagination.Default;// default to volian default
return (SectionPagination)int.Parse(s);
}
set
{
// if value being saved is same as the parent value, then clear the value (save blank). This will
// reset the data to use the parent value.
string parval = _Xp.ParentValue("Section", "Pagination"); // get the parent value
if (parval.Equals(string.Empty)) // if the parent value is empty, then use the volian default
parval = ((int)(SectionPagination.Default)).ToString();
if (parval.Equals(((int)value).ToString()))
_Xp["Section", "Pagination"] = string.Empty; // reset to parent value
else
_Xp["Section", "Pagination"] = ((int)value).ToString(); // save selected value
OnPropertyChanged("Section_Pagination");
}
}
[Category("View Settings")]
//PROPGRID: Hide Include in Background/Deviation
[Browsable(false)]
[DisplayName("Include in Background/Deviation")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section LinkEnhanced")]
public string Section_LnkEnh
{
get
{
return _Xp["Section", "LnkEnh"];
}
set
{
_Xp["Section", "LnkEnh"] = value;
OnPropertyChanged("Section_LnkEnh");
}
}
[Category("General")]
//PROPGRID: Hide Include On Table Of Contents
[Browsable(false)]
[DisplayName("Include On Table Of Contents")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section TOC")]
public string Section_TOC
{
get
{
return _Xp["Section", "TOC"];
}
set
{
_Xp["Section", "TOC"] = value;
OnPropertyChanged("Section_TOC");
}
}
[Category("Section")]
//PROPGRID: Hide AutoGen
[Browsable(false)]
[DisplayName("Section AutoGen")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section AutoGen")]
public string Section_AutoGen
{
get
{
return _Xp["Section", "AutoGen"];
}
set
{
_Xp["Section", "AutoGen"] = value;
OnPropertyChanged("Section_AutoGen");
}
}
[Category("Section")]
//PROPGRID: Hide Section NumPages
[Browsable(false)]
[DisplayName("Section NumPages")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section NumPages")]
public string Section_NumPages
{
get
{
return _Xp["Section", "NumPages"];
}
set
{
_Xp["Section", "NumPages"] = value;
OnPropertyChanged("Section_NumPages");
}
}
[TypeConverter(typeof(EnumDescConverter))]
public enum SectionColumnMode : int
{
Default = 0,
[Description("Single Column")]
One = 1,
[Description("Dual Column")]
Two = 2,
[Description("Triple Column")]
Three = 3,
[Description("Quad Column")]
Four = 4
}
[Category("Format")]
[DisplayName("Columns")]
[RefreshProperties(RefreshProperties.All)]
[Description("Section ColumnMode")]
public SectionColumnMode Section_ColumnMode
{
get
{
string s = _Xp["Section", "ColumnMode"];
//If there is no value to get, then get the parent value (a.k.a. default value).
if (s == string.Empty)
s = _Xp.ParentValue("Section", "ColumnMode"); // get the parent value
// If there is no parent value, then use the volian default
if (s == string.Empty)
return SectionColumnMode.Default;// default to volian default
return (SectionColumnMode)int.Parse(s);
}
set
{
// if value being saved is same as the parent value, then clear the value (save blank). This will
// reset the data to use the parent value.
string parval = _Xp.ParentValue("Section", "ColumnMode"); // get the parent value
if (parval.Equals(string.Empty)) // if the parent value is empty, then use the volian default
parval = ((int)(SectionColumnMode.Default)).ToString();
if (parval.Equals(((int)value).ToString()))
_Xp["Section", "ColumnMode"] = string.Empty; // reset to parent value
else
_Xp["Section", "ColumnMode"] = ((int)value).ToString(); // save selected value
OnPropertyChanged("Section_ColumnMode");
}
}
#endregion
#region SubSectionCategory // from sequence number in 16-bit database.
[Category("SubSection")]
//PROPGRID: Hide SubSection Edit
[Browsable(false)]
[DisplayName("SubSection Edit")]
[RefreshProperties(RefreshProperties.All)]
[Description("SubSection Edit")]
public string SubSection_Edit
{
get
{
return _Xp["SubSection", "Edit"];
}
set
{
_Xp["SubSection", "Edit"] = value;
OnPropertyChanged("SubSection_Edit");
}
}
[Category("SubSection")]
//PROPGRID: Hide Subsection PH
[Browsable(false)]
[DisplayName("SubSection PH")]
[RefreshProperties(RefreshProperties.All)]
[Description("SubSection PH")]
public string SubSection_PH
{
get
{
return _Xp["SubSection", "PH"];
}
set
{
_Xp["SubSection", "PH"] = value;
OnPropertyChanged("SubSection_PH");
}
}
[Category("SubSection")]
//PROPGRID: Hide Subsection AutoIndent
[Browsable(false)]
[DisplayName("SubSection AutoIndent")]
[RefreshProperties(RefreshProperties.All)]
[Description("SubSection AutoIndent")]
public string SubSection_AutoIndent
{
get
{
return _Xp["SubSection", "AutoIndent"];
}
set
{
_Xp["SubSection", "AutoIndent"] = value;
OnPropertyChanged("SubSection_AutoIndent");
}
}
#endregion
#region LibDocCategory // from library document file during migration
[Category("LibraryDocument")]
//PROPGRID: Hide Libary Document Comment
[Browsable(false)]
[DisplayName("LibraryDocument Comment")]
[RefreshProperties(RefreshProperties.All)]
[Description("LibraryDocument Comment")]
public string LibDoc_Comment
{
get
{
return _Xp["LibraryDocument", "Comment"];
}
set
{
_Xp["LibraryDocument", "Comment"] = value;
OnPropertyChanged("LibDoc_Comment");
}
}
#endregion
}
}