Files
SourceCode/PROMS/VEPROMS.CSLA.Library/Config/StepConfig.cs
T
2026-08-28 11:15:35 -04:00

594 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;
namespace VEPROMS.CSLA.Library
{
public partial class EnhancedDocuments : List<EnhancedDocument>
{
public void Add(int type, int itemID) => Add(new EnhancedDocument(type, itemID));
public static EnhancedDocuments Load(XMLProperties _Xp)
{
EnhancedDocuments ed = new EnhancedDocuments();
foreach (XmlNode xn in _Xp.XmlContents.SelectNodes("//Enhanced"))
{
ed.Add(int.Parse(xn.Attributes["Type"].Value), int.Parse(xn.Attributes["ItemID"].Value));
}
return ed;
}
public EnhancedDocument GetByType(int type)
{
foreach (EnhancedDocument ed in this)
if (ed.Type == type) return ed;
return null;
}
}
public partial class EnhancedDocument
{
public int Type { get; set; }
public int ItemID { get; set; }
public EnhancedDocument() { ;}
public EnhancedDocument(int type, int itemID)
{
Type = type;
ItemID = itemID;
}
public override string ToString() => $"{Type}.ItemID={ItemID}";
}
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class StepConfig : ConfigDynamicTypeDescriptor, INotifyPropertyChanged, IItemConfig
{
#region DynamicTypeDescriptor
internal override bool IsReadOnly => false;
#endregion
#region XML
private readonly XMLProperties _Xp;
#endregion
#region Constructors
//PROPGRID: Hide ParentLookup
[Browsable(false)]
public bool ParentLookup
{
get { return _Xp.ParentLookup; }
set { _Xp.ParentLookup = value; }
}
private readonly Step _Step;
private readonly StepInfo _StepInfo;
public StepConfig(Step step)
{
_Step = step;
string xml = step.MyContent.Config;
if (xml == string.Empty) xml = "<Config/>";
_Xp = new XMLProperties(xml);
}
public StepConfig(StepInfo stepInfo)
{
_StepInfo = stepInfo;
string xml = stepInfo.MyContent.Config;
if (xml == string.Empty) xml = "<Config/>";
_Xp = new XMLProperties(xml);
}
public StepConfig(string xml)
{
if (xml == string.Empty) xml = "<Config/>";
_Xp = new XMLProperties(xml);
}
public StepConfig() => _Xp = new XMLProperties();
internal string GetValue(string group, string item) => _Xp[group, item];
#endregion
#region Local Properties
#endregion
#region ToString
public override string ToString()
{
string s = _Xp.ToString();
return s == "<Config/>" || s == "<Config></Config>" ? string.Empty : s;
}
#endregion
#region StepAttr
public int Step_FloatingFoldout
{
get
{
string s = _Xp["Step", "FloatingFoldout"];
if (s == string.Empty) return 0;
int tst;
try
{
tst = int.Parse(s);
}
catch (Exception)
{
return 0;
}
return tst;
}
set
{
string s = _Xp["Step", "FloatingFoldout"];
if (value.ToString() == s) return;
_Xp["Step", "FloatingFoldout"] = value.ToString();
OnPropertyChanged("Step_FloatingFoldout");
}
}
public string Step_CAS
{
get
{
string s = _Xp["Step", "ContActSum"];
//If there is no value in the config, then return null. This will tell us to check the step type and format flag (ExcludeFromContActSum).
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "ContActSum"];
if (value == s) return;
_Xp["Step", "ContActSum"] = value;
OnPropertyChanged("Step_CAS");
}
}
// F2022-024 Time Critical Action Step
public string Step_TCAS // Time Critical Action Summary
{
get
{
string s = _Xp["Step", "TimeCriticalActionSum"];
//If there is no value in the config, then return null. This will tell us to check the step type and format flag (ExcludeFromTimeCriticalActSum).
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "TimeCriticalActionSum"];
if (value == s) return;
_Xp["Step", "TimeCriticalActionSum"] = value;
OnPropertyChanged("Step_TCAS");
}
}
public string Step_Placekeeper
{
get
{
string s = _Xp["Step", "Placekeeper"];
//If there is no value to get, then get the parent value (a.k.a. default value).
if (s == string.Empty) return "N";
return s;
}
set
{
string s = _Xp["Step", "Placekeeper"];
if (value == s) return;
_Xp["Step", "Placekeeper"] = value;
OnPropertyChanged("Step_Placekeeper");
}
}
public int Step_CheckOffIndex
{
get
{
string s = _Xp["Step", "CheckOffIndex"];
if (s == string.Empty) return 0;
// there was an invalid character for Wolf Creek's index. just return
// a 0 if found. The dataloader was fixed (6/8/12) to not migrate the
// bad character, but this was added, in case there are some other conditions.
if (int.TryParse(s, out int tst))
return tst;
tst = (int) s[0];
tst -= '0';
return tst;
}
set
{
string s = _Xp["Step", "CheckOffIndex"];
if (value.ToString() == s) return;
_Xp["Step", "CheckOffIndex"] = value.ToString();
OnPropertyChanged("Step_CheckOffIndex");
}
}
public bool Step_ManualPagebreak
{
get
{
string s = _Xp["Step", "ManualPagebreak"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "ManualPagebreak"];
if (value.ToString() == s) return;
_Xp["Step", "ManualPagebreak"] = value.ToString();
OnPropertyChanged("Step_ManualPagebreak");
}
}
public bool Step_NewManualPagebreak
{
get
{
string s = _Xp["Step", "NewManualPagebreak"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "NewManualPagebreak"];
if (value.ToString() == s) return;
_Xp["Step", "NewManualPagebreak"] = value.ToString();
OnPropertyChanged("Step_NewManualPagebreak");
}
}
public bool Step_PreferredPagebreak
{
get
{
string s = _Xp["Step", "PreferredPagebreak"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "PreferredPagebreak"];
if (value.ToString() == s) return;
_Xp["Step", "PreferredPagebreak"] = value.ToString();
OnPropertyChanged("Step_PreferredPagebreak");
}
}
// C2023-015: Pagination on a sub-step
public bool Step_SubStepPagebreak
{
get
{
string s = _Xp["Step", "SubStepPagebreak"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "SubStepPagebreak"];
if (value.ToString() == s) return;
_Xp["Step", "SubStepPagebreak"] = value.ToString();
OnPropertyChanged("Step_SubStepPagebreak");
}
}
public string Step_CBOverride
{
get
{
string s = _Xp["Step", "CBOverride"];
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "CBOverride"];
if (value != null && value.ToString() == s) return;
if (value == null && s != null) _Xp["Step", "CBOverride"] = null;
else _Xp["Step", "CBOverride"] = value.ToString();
OnPropertyChanged("Step_CBOverride");
}
}
public string Step_ChangeID
{
get
{
string s = _Xp["Step", "ChangeID"];
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "ChangeID"];
if (value != null && value.ToString() == s) return;
if (value == null && s != null) _Xp["Step", "ChangeID"] = null;
else _Xp["Step", "ChangeID"] = value.ToString();
OnPropertyChanged("Step_ChangeID");
}
}
// C2015-028 Add Editorial Mode to PROMS Step Editor
// was last change made in editorial mode and thus change bars should be disabled?
// will contain userid of user that made last change if it was in Editorial Mode
// if there was not a previous change that would have caused change bars
// will be blank/empty by default
// will get overwritten every time a change is made
public string Step_ChangeIDEditorialMode
{
get
{
string s = _Xp["Step", "ChangeIDEMode"];
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "ChangeIDEMode"];
if (value != null && value.ToString() == s) return;
if (value == null && s != null) _Xp["Step", "ChangeIDEMode"] = null;
else _Xp["Step", "ChangeIDEMode"] = value.ToString();
OnPropertyChanged("Step_ChangeIDEMode");
}
}
public string Step_Responsibility
{
get
{
string s = _Xp["Step", "Responsibility"];
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "Responsibility"];
if (value != null && value.ToString() == s) return;
if (value == null && s != null) _Xp["Step", "Responsibility"] = null;
else _Xp["Step", "Responsibility"] = value.ToString();
OnPropertyChanged("Step_Responsibility");
}
}
// When the spell checker changes text do not assign a change bar but keep existing change bar if it is there
public string Step_SpellCheckerChangedText
{
get
{
string s = _Xp["Step", "SpellCheckerChangedText"];
if (s == string.Empty) return null;
return s;
}
set
{
string s = _Xp["Step", "SpellCheckerChangedText"];
if (value != null && value.ToString() == s) return;
if (value == null && s != null) _Xp["Step", "SpellCheckerChangedText"] = null;
else _Xp["Step", "SpellCheckerChangedText"] = value.ToString();
OnPropertyChanged("SpellCheckerChangedText");
}
}
// C2021-015: Barakah High Level Steps in Table of Contents
public bool Step_IncludeInTOC
{
get
{
string s = _Xp["Step", "IncludeInTOC"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "IncludeInTOC"];
if (value.ToString() == s) return;
_Xp["Step", "IncludeInTOC"] = value.ToString();
OnPropertyChanged("Step_IncludeInTOC");
}
}
public bool Step_FixedTblForSrch
{
get
{
string s = _Xp["Step", "FixedTblForSrch"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "FixedTblForSrch"];
if (value.ToString() == s) return;
_Xp["Step", "FixedTblForSrch"] = value.ToString();
OnPropertyChanged("Step_FixedTblForSrch");
}
}
//CSM F2024-080: For South Texas - Ability to toggle off Initial Line
public bool Step_DisableInitialLine
{
get
{
string s = _Xp["Step", "DisableInitialLine"];
if (s == string.Empty) return false;
if (s == "True") return true;
return false;
}
set
{
string s = _Xp["Step", "DisableInitialLine"];
if (value.ToString() == s) return;
_Xp["Step", "DisableInitialLine"] = value.ToString();
OnPropertyChanged("Step_DisableInitialLine");
}
}
//C2019-025 Ability to Toggle Replace Words
public int Step_ShwRplWdsIndex
{
get
{
string s = _Xp["Step", "ShwRplWdsIndex"];
if (s == string.Empty) return 0;
if (s == "0") return 0;
if (s == "1") return 1;
if (s == "2") return 2;
if (s == "3") return 3;
return 0;
}
set
{
string s = _Xp["Step", ""];
if (value.ToString() == s) return;
_Xp["Step", "ShwRplWdsIndex"] = value.ToString();
OnPropertyChanged("Step_ShwRplWdsIndex");
}
}
#region RO image sizing
// if the RO image (figure) is resized, save it in the step config, not in the ROImageConfig. If stored in ROImageConfig
// the size is set for ALL uses.
public int Step_ImageWidth
{
get
{
string s = _Xp["Step", "ImageWidth"];
if (s == string.Empty) return 0;
int tst;
try
{
tst = int.Parse(s);
}
catch (Exception)
{
return 0;
}
return tst;
}
set
{
string s = _Xp["Step", "ImageWidth"];
if (value.ToString() == s) return;
_Xp["Step", "ImageWidth"] = value.ToString();
OnPropertyChanged("Step_ImageWidth");
}
}
public int Step_ImageHeight
{
get
{
string s = _Xp["Step", "ImageHeight"];
if (s == string.Empty) return 0;
int tst;
try
{
tst = int.Parse(s);
}
catch (Exception)
{
return 0;
}
return tst;
}
set
{
string s = _Xp["Step", "ImageHeight"];
if (value.ToString() == s) return;
_Xp["Step", "ImageHeight"] = value.ToString();
OnPropertyChanged("Step_ImageHeight");
}
}
#endregion
// Enhanced Documents
private EnhancedDocuments _MyEnhancedDocuments = null;
public EnhancedDocuments MyEnhancedDocuments
{
get
{
if (_MyEnhancedDocuments == null)
{
_MyEnhancedDocuments = EnhancedDocuments.Load(_Xp);
}
return _MyEnhancedDocuments;
}
set
{
_MyEnhancedDocuments = value;
}
}
public void AddEnhancedDocument(int type, int itemid)
{
MyEnhancedDocuments.Add(type, itemid);
SaveEnhancedDocuments();
}
public void SaveEnhancedDocuments()
{
// get all of the current enhanced links from datastructure in code. This list may have been
// modified by adding items during code execution by associating source <--> background etc.
EnhancedDocuments edsToAdd = new EnhancedDocuments();
foreach (EnhancedDocument ed in MyEnhancedDocuments)
edsToAdd.Add(ed);
// from the existing list in xml, remove any that are in the 'editted (edsToAdd) list
// so that what remains are those that need added to xml that will then be written to database
foreach (XmlNode xn in _Xp.XmlContents.SelectNodes("//Enhanced"))
{
EnhancedDocument tmp = edsToAdd.GetByType(int.Parse(xn.Attributes["Type"].Value));
if (tmp != null)
{
if (int.Parse(xn.Attributes["ItemID"].Value) != tmp.ItemID)
xn.Attributes["ItemID"].Value = tmp.ItemID.ToString();
edsToAdd.Remove(tmp);
}
}
foreach (EnhancedDocument edadd in edsToAdd)
{
// Add (example): <Enhanced Type="Background" ItemID="43138" /><Enhanced Type="Deviation" ItemID="67165" />
// First add 'Enhanced' element:
XmlNode newEnhNode = _Xp.XmlContents.CreateNode(XmlNodeType.Element, "Enhanced", _Xp.XmlContents.NamespaceURI);
XmlNode xnEnh = _Xp.XmlContents.DocumentElement.AppendChild(newEnhNode);
// Now add the 'Type' and 'ItemID' attributes:
XmlAttribute xa = xnEnh.Attributes.Append(_Xp.XmlContents.CreateAttribute("Type"));
xa.Value = edadd.Type.ToString();
xa = xnEnh.Attributes.Append(_Xp.XmlContents.CreateAttribute("ItemID"));
xa.Value = edadd.ItemID.ToString();
}
}
#endregion
#region IItemConfig Members
[Category("Master/Slave Settings")]
[DisplayName("Applicability")]
[RefreshProperties(RefreshProperties.All)]
[Description("Scope Applicability")]
public Volian.Base.Library.BigNum MasterSlave_Applicability
{
get
{
string s = _Xp["MasterSlave", "Applicability"];
return new Volian.Base.Library.BigNum(s);
}
set
{
if (value != null)
_Xp["MasterSlave", "Applicability"] = value.FlagList;
else
_Xp["MasterSlave", "Applicability"] = null;
OnPropertyChanged("MasterSlave_Applicability");
}
}
#endregion
}
}